Commit fa377522 authored by L. Ellenbeck's avatar L. Ellenbeck
Browse files

WIP: Fixed tests coscine/issues#1115

parent bea6af9b
......@@ -21,19 +21,22 @@ namespace Coscine.Api.Project.Tests
{
private static ILogger<ProjectController> projectLogger = null;
private static ILogger<ProjectController> ProjectLogger { get
private static ILogger<ProjectController> ProjectLogger
{
if (projectLogger == null)
get
{
CoscineLoggerConfiguration.SetConfig();
projectLogger = new NullLogger<ProjectController>();
if (projectLogger == null)
{
CoscineLoggerConfiguration.SetConfig();
projectLogger = new NullLogger<ProjectController>();
}
return projectLogger;
}
return projectLogger;
} }
}
public ProjectControllerTests() : base(new ProjectController(ProjectLogger))
{
}
[Test]
......@@ -55,19 +58,20 @@ namespace Coscine.Api.Project.Tests
[Test]
public void TestControllerIndex()
{
var actionResult = Controller.Index();
var actionResult = Controller.Index().Result;
Assert.IsTrue(actionResult.GetType() == typeof(OkObjectResult));
}
[Test]
public void TestControllerGet()
{
var actionResult = Controller.Get(Projects[0].Id.ToString());
Assert.IsTrue(actionResult.GetType() == typeof(ActionResult<ProjectObject>));
var actionResult = Controller.Get(Projects[0].Id.ToString()).Result;
Assert.IsTrue(actionResult.GetType() == typeof(OkObjectResult));
Assert.IsTrue(actionResult.Value.GetType() == typeof(ProjectObject));
OkObjectResult okObjectResult = (OkObjectResult)actionResult;
Assert.IsTrue(okObjectResult.Value.GetType() == typeof(ProjectObject));
ProjectObject projectObject = actionResult.Value;
ProjectObject projectObject = (ProjectObject)okObjectResult.Value;
Assert.IsTrue(projectObject.Id == Projects[0].Id);
Assert.IsTrue(projectObject.Description == Projects[0].Description);
......@@ -82,8 +86,8 @@ namespace Coscine.Api.Project.Tests
[Test]
public void TestControllerUpdate()
{
var actionResult = Controller.Get(Projects[0].Id.ToString());
ProjectObject projectObject = actionResult.Value;
var actionResult = Controller.Get(Projects[0].Id.ToString()).Result;
ProjectObject projectObject = (ProjectObject)((OkObjectResult)actionResult).Value;
projectObject.Description = "ChangedDescription";
......@@ -111,7 +115,7 @@ namespace Coscine.Api.Project.Tests
[Test]
public void TestControllerStore()
{
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
ProjectObject newProjectObject = new ProjectObject(Guid.NewGuid(), "NewProject", "NewDisplayName", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayNameDe, Discipline.DisplayNameEn) },
new List<OrganizationObject>() { new OrganizationObject(Organization, Organization) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName), Guid.NewGuid().ToString());
......@@ -180,7 +184,7 @@ namespace Coscine.Api.Project.Tests
stream.Close();
Controller.DeleteProject(project, true);
}
[Test]
public void TestControllerDeleteWithSubProjects()
{
......@@ -246,7 +250,7 @@ namespace Coscine.Api.Project.Tests
ProjectObject newSubProjectObject = new ProjectObject(Guid.NewGuid(), "NewSubProject", "NewDisplayNameSub", DateTime.Now, DateTime.Now.AddYears(1), "test2;test3", "abc", "investigator", "grandId",
new List<DisciplineObject>() { new DisciplineObject(Discipline.Id, Discipline.Url, Discipline.DisplayNameDe, Discipline.DisplayNameEn) },
new List<OrganizationObject>() { new OrganizationObject(Organization, Organization) },
new VisibilityObject(Visibility.Id, Visibility.DisplayName), Guid.NewGuid().ToString(),
new VisibilityObject(Visibility.Id, Visibility.DisplayName), Guid.NewGuid().ToString(),
createdProjectObject.Id);
var subStream = ObjectFactory<ProjectObject>.SerializeToStream(newSubProjectObject);
......@@ -258,7 +262,7 @@ namespace Coscine.Api.Project.Tests
SubProjectModel subProjectModel = new SubProjectModel();
var subProjects = subProjectModel.GetAllWhere((x) => x.ProjectId == createdProjectObject.Id);
foreach(var subProject in subProjects)
foreach (var subProject in subProjects)
{
Assert.IsTrue(subProject.SubProjectId == createdSubProjectObject.Id);
Assert.IsTrue(subProject.ProjectId == createdProjectObject.Id);
......@@ -280,4 +284,4 @@ namespace Coscine.Api.Project.Tests
Assert.IsTrue(Previous == projectModel.GetAll().ToArray().Length - Projects.Count);
}
}
}
\ No newline at end of file
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment