public void Return_list_of_collections_for_get_to_index(SourceProjectType projectType) { DataDeposit dd = projectType == SourceProjectType.DEPOSIT ? Builder<DataDeposit>.CreateNew().Build() : null; DataManagementPlan dmp = projectType == SourceProjectType.DMP ? Builder<DataManagementPlan>.CreateNew().Build() : null; // Arrange var collections = Builder<DataCollection>.CreateListOfSize(2) .TheFirst(1) .With(dc => dc.CurrentState = new DataCollectionState(DataCollectionStatus.Draft, DateTime.Now)) .And(dc => dc.IsFirstCollection = true) .TheNext(1) .With(dc => dc.CurrentState = new DataCollectionState(DataCollectionStatus.Draft, DateTime.Now)) .And(dc => dc.IsFirstCollection = false) .Build(); var project = Builder<Project>.CreateNew() .With(p => p.Id = ProjectId) .And(p => p.DataManagementPlan = dmp) .And(p => p.DataDeposit = dd) .And(p => p.DataCollections.AddRange(collections)) .And(p => p.SourceProjectType = projectType) .Build(); _projectRepository.Get(project.Id).Returns(project); _dataCollectionRepository.GetByProject(project.Id).Returns(collections); // Act _controller.WithCallTo(c => c.Index(ProjectId)).ShouldRenderDefaultView() .WithModel<DataCollectionListViewModel>(m => { Assert.That(m.ProjectId, Is.EqualTo(project.Id), "Project ID not correct"); Assert.That(m.ProjectTitle, Is.EqualTo(project.Title), "Project title not correct"); Assert.That( m.DataCollectionItems.Count(), Is.EqualTo(collections.Count)); collections.Do( c => Assert.That( m.DataCollectionItems.Any( cc => cc.Id == c.Id))); return true; }); _projectRepository.Received().Get(Arg.Is(project.Id)); _dataCollectionRepository.Received().GetByProject(Arg.Is(project.Id)); _dataCollectionRepository.DidNotReceive().Get(Arg.Any<int>()); }
public void Send_submit_for_approval_command_to_bus(SourceProjectType projectType) { DataDeposit dd = projectType == SourceProjectType.DEPOSIT ? Builder<DataDeposit>.CreateNew().Build() : null; DataManagementPlan dmp = projectType == SourceProjectType.DMP ? Builder<DataManagementPlan>.CreateNew().Build() : null; var project = SetUpFullProjectWithAuthentication(); project.SourceProjectType = projectType; project.DataDeposit = dd; project.DataManagementPlan = dmp; var collections = SetUpFullDataCollections(project, 2).ToList(); collections.ForEach(o => o.CurrentState = new DataCollectionState(DataCollectionStatus.Submitted, DateTime.Now)); // Arrange var vm = Builder<DataCollectionListViewModel> .CreateNew() .With(o => o.ProjectId = project.Id) .And(o => o.DataCollectionItems = Builder<DataCollectionItemViewModel>.CreateListOfSize(3).Build()) .Build(); var collection = collections[1]; _bus.When(c => c.Send(Arg.Any<Action<SubmitForApproval>>())).Do(a => { // Trace.WriteLine("Collection Id: " + collection.Id); // Arrange var rsc = new SubmitForApproval(); var lambda = a.Arg<Action<SubmitForApproval>>(); // Act lambda(rsc); Trace.WriteLine("Collection Id: " + collection.Id + " rsc: " + rsc.DataCollectionId); // Assert Assert.That(rsc.DataCollectionId, Is.EqualTo(collection.Id), "Invalid collection id passed to the bus"); Assert.That(rsc.ApprovedOn, Is.EqualTo(collection.CurrentState.StateChangedOn).Within(1).Minutes, "Invalid submission date passed to the bus"); Assert.That(rsc.ApprovedBy, Is.EqualTo(collection.Parties.Single(o => o.Relationship == DataCollectionRelationshipType.Manager).Party.UserId), "Invalid manager id passed to the bus"); }); // Act _projectRepository.Get(vm.ProjectId).Returns(project); _dataCollectionRepository.Get(collections[0].Id).Returns(collections[0]); _dataCollectionRepository.Get(collections[1].Id).Returns(collections[1]); // Assert _controller.WithCallTo(c => c.Index(vm)).ShouldRenderView("Submitted").WithModel<SubmittedDataCollectionsViewModel>((m => { Assert.That(ModelCollectionIsEqualTo(vm, m)); return true; })); _bus.Received().Send(Arg.Any<Action<SubmitForApproval>>()); }
public void Return_NotSubmitted_for_a_post_to_step1_when_attempting_to_create_a_data_collection_and_the_first_collection_is_not_created(SourceProjectType projectType, string notSubmittedView) { DataDeposit dd = projectType == SourceProjectType.DEPOSIT ? Builder<DataDeposit>.CreateNew().Build() : null; DataManagementPlan dmp = projectType == SourceProjectType.DMP ? Builder<DataManagementPlan>.CreateNew().Build() : null; CreateUser("XX12345"); var project = Builder<Project>.CreateNew() .With(o => o.SourceProjectType = projectType) .And(o => o.DataManagementPlan = dmp) .And(o => o.DataDeposit = dd) .Build(); _projectRepository.Get(project.Id).Returns(project); var vm = Builder<DataCollectionViewModelStep1>.CreateNew() .With(o => o.ProjectId = project.Id) .And(o => o.Id = 0) .And(o => o.ProjectTitle = project.Title) .Build(); _controller.WithCallTo(c => c.Step1(vm)) .ShouldRenderView(notSubmittedView); _projectRepository.Received().Get(Arg.Is(project.Id)); _dataCollectionRepository.DidNotReceive().Get(Arg.Any<int>()); _dataCollectionRepository.DidNotReceive().GetByProject(Arg.Any<int>()); _dataCollectionRepository.DidNotReceive().Save(Arg.Any<DataCollection>()); }
public void Save_model_for_new_collection_and_redirect_to_next_step_on_post_to_step1(SourceProjectType projectType) { const string userId = "XX12345"; const int id = 1; CreateUser(userId); var objectives = Builder<SocioEconomicObjective>.CreateListOfSize(5).Build().Select(q => new ProjectSocioEconomicObjective {SocioEconomicObjective = q}); var fieldsOfResearch = Builder<FieldOfResearch>.CreateListOfSize(6).Build().Select(q => new ProjectFieldOfResearch {FieldOfResearch = q}); var dataCollection = Builder<DataCollection>.CreateNew() .With(o => o.ProjectId = id) .And(o => o.IsFirstCollection = true) .Build(); _dataCollectionRepository.Get(dataCollection.Id).Returns(dataCollection); var project = Builder<Project>.CreateNew() .With(o => o.Id = id) .And(o => o.SourceProjectType = projectType) .And(o => o.DataManagementPlan = Builder<DataManagementPlan>.CreateNew().Build()) .And(o => o.SocioEconomicObjectives.AddRange(objectives)) .And(o => o.FieldsOfResearch.AddRange(fieldsOfResearch)) .And(o => o.DataCollections.Add(dataCollection)) .Build(); var vm = Builder<DataCollectionViewModelStep1>.CreateNew() .With(o => o.Id = 0) .And(o => o.ProjectId = project.Id) .Build(); _projectRepository.Get(project.Id).Returns(project); _controller.WithCallTo(c => c.Step1(vm)) .ShouldRedirectTo(_controller.GetType().GetMethod("Step2", new[] { typeof(int), typeof(int) })); _dataCollectionRepository.DidNotReceive().Get(Arg.Is(dataCollection.Id)); _projectRepository.Received().Get(Arg.Is(project.Id)); _dataCollectionRepository.Received().Save(Arg.Is<DataCollection>(o => o.Id == 0)); _dataCollectionRepository.Received().Save(Arg.Is<DataCollection>(o => o.FieldsOfResearch.All(q => fieldsOfResearch.SingleOrDefault(r => r.FieldOfResearch.Id == q.FieldOfResearch.Id) != null))); _dataCollectionRepository.Received().Save(Arg.Is<DataCollection>(o => o.SocioEconomicObjectives.All(q => objectives.SingleOrDefault(r => r.SocioEconomicObjective.Id == q.SocioEconomicObjective.Id) != null))); }
public void Redirect_to_read_only_view_if_data_collection_not_in_draft_state_on_get_to_step1(SourceProjectType projectType) { const int id = 1; var dataCollection = Builder<DataCollection>.CreateNew() .With(dc => dc.ProjectId = id) .And(dc => dc.CurrentState = new DataCollectionState(DataCollectionStatus.Submitted, DateTime.Now)) .And(dc => dc.IsFirstCollection = true) .Build(); var project = Builder<Project>.CreateNew() .With(p => p.Id = id) .And(p => p.DataManagementPlan = Builder<DataManagementPlan>.CreateNew().Build()) .And(p => p.SourceProjectType = projectType) .And(p => p.DataCollections.Add(dataCollection)) .Build(); _projectRepository.Get(project.Id).Returns(project); _dataCollectionRepository.Get(dataCollection.Id).Returns(dataCollection); _controller.WithCallTo(c => c.Step1(project.Id, dataCollection.Id)) .ShouldRedirectTo(_controller.GetType().GetMethod("ViewReadOnlyDataCollection", new[] { typeof(int), typeof(int) })); _projectRepository.Received().Get(Arg.Is(project.Id)); _dataCollectionRepository.Received().Get(Arg.Is(dataCollection.Id)); }
public void Return_NoSubmission_for_post_to_index_when_first_collection_not_created(SourceProjectType projectType, string notSubmittedView) { DataDeposit dd = projectType == SourceProjectType.DEPOSIT ? Builder<DataDeposit>.CreateNew().Build() : null; DataManagementPlan dmp = projectType == SourceProjectType.DMP ? Builder<DataManagementPlan>.CreateNew().Build() : null; var project = Builder<Project>.CreateNew() .With(o => o.SourceProjectType = projectType) .And(o => o.DataManagementPlan = dmp) .And(o => o.DataDeposit = dd) .Build(); var vm = Builder<DataCollectionListViewModel>.CreateNew() .With(o => o.ProjectId = project.Id) .And(o => o.ProjectTitle = project.Title) .Build(); _projectRepository.Get(project.Id).Returns(project); _controller.WithCallTo(c => c.Index(vm)) .ShouldRenderView(notSubmittedView); _projectRepository.Received().Get(Arg.Is(project.Id)); _dataCollectionRepository.DidNotReceive().GetByProject(Arg.Is(project.Id)); _dataCollectionRepository.DidNotReceive().Save(Arg.Any<DataCollection>()); }
public static SourceProject FromText(IEnumerable <string> content, string name, string output, SourceProjectType projectType) => new SourceProject(name, output, projectType, SourceProjectFile.FromText(ToSingleText(content)));
public void SetProgramType(SourceProjectType type) => this.m_projType = type;