public void Given_empty_array_of_longs_posted_When_SelectResponsibilities_Then_put_message_in_tempdata()
        {
            // Given
            _target = GetTarget();

            // When
            var result = _target.SelectResponsibilities(new long[] { }) as RedirectToRouteResult;

            // Then
            Assert.That(_target.TempData["alertMessage"], Is.EqualTo("Please select at least one Responsibility to generate"));
        }
        public void Given_array_of_responsibility_ids_When_GenerateResponsibilities_Then_pass_array_to_view_model_factory()
        {
            // Given
            _target = GetTarget();

            // When
            var result = _target.GenerateResponsibilities(string.Join(",", _selectedResponsibilityIds));

            // Then
            _generateResponsibilitiesViewModelFactory.Verify(x => x.WithResponsibilityTemplateIds(_selectedResponsibilityIds));
        }
        public void Given_valid_model_When_GenerateResponsibilities_Then_pass_request_to_service()
        {
            // Given
            _target = GetTarget();

            // When
            _target.GenerateResponsibilities(_model);
            
            // Then
            _responsibilitiesService.Verify(x => x.CreateResponsibilitiesFromWizard(It.IsAny<CreateResponsibilityFromWizardRequest>()));
        }
        public void Given_null_array_of_longs_posted_When_SelectResponsibilities_Then_redirect_to_SelectResponsibilities_action()
        {
            // Given
            _target = GetTarget();

            // When
            var result = _target.SelectResponsibilities(new long[0]);
            var redirectResult = result as RedirectToRouteResult;

            // Then
            Assert.That(result, Is.InstanceOf<RedirectToRouteResult>());
            Assert.That(redirectResult.RouteValues["Action"], Is.EqualTo("SelectResponsibilities"));
        }
        public void Given_array_of_responsibility_ids_When_GenerateResponsibilities_Then_return_ViewResult()
        {
            // Given
            _target = GetTarget();
            _target.TempData["selectedResponsibilities"] = _selectedResponsibilityIds;

            // When
            var result = _target.GenerateResponsibilities(string.Join(",", _selectedResponsibilityIds));

            var viewResult = result as ViewResult;

            // Then
            Assert.That(result,Is.InstanceOf<ViewResult>());
            Assert.That(viewResult.ViewName == String.Empty);
        }
        public void Given_valid_model_When_GenerateResponsibilities_Then_map_save_request()
        {
            // Given
            _target = GetTarget();

            // When
            _target.GenerateResponsibilities(_model);

            // Then
            _responsibilitiesService.Verify(x => x.CreateResponsibilitiesFromWizard(It.Is<CreateResponsibilityFromWizardRequest>(y =>
                y.CompanyId == TestControllerHelpers.CompanyIdAssigned &&
                y.SiteIds == _model.SiteIds &&
                y.UserId == TestControllerHelpers.UserIdAssigned
            )));
        }
        public void Given_model_with_Responsibilities_with_null_ResponsibilityTemplateId_When_GenerateResponsibilities_Then_add_error_to_modelstate()
        {
            // Given
            var modelWithNoResponsibilities = _model;
            modelWithNoResponsibilities.Responsibilities = new List<ConfiguredResponsibilityFromTemplate>()
                                                           {
                                                               new ConfiguredResponsibilityFromTemplate()
                                                               {
                                                                   FrequencyId = TaskReoccurringType.SixMonthly,
                                                                   ResponsiblePersonEmployeeId = Guid.NewGuid(),
                                                                   ResponsibilityTemplateId = default(long)
                                                               }
                                                           };

            _target = GetTarget();

            // When
            _target.GenerateResponsibilities(modelWithNoResponsibilities);

            // Then
            Assert.That(_target.ModelState.IsValid, Is.False);
        }
 private WizardController GetTarget()
 {
     var controller = new WizardController(null, _generateResponsibilitiesViewModelFactory.Object,
                                           _generateResponsibilityTasksViewModelFactory.Object, null, null, null);
     return TestControllerHelpers.AddUserWithDefinableAllowedSitesToController(controller, _allowedSites);
 }
        public void Given_array_of_responsibility_ids_When_GenerateResponsibilities_Then_pass_model_from_factory_to_view()
        {
            // Given
            _target = GetTarget();
            _target.TempData["selectedResponsibilities"] = _selectedResponsibilityIds;

            // When
            var result = _target.GenerateResponsibilities(string.Join(",", _selectedResponsibilityIds));
            var viewResult = result as ViewResult;

            // Then
            Assert.That(viewResult.Model, Is.EqualTo(_returnedViewModel));
        }
        public void Given_array_of_responsibility_ids_When_GenerateResponsibilities_Then_pass_current_users_allowed_sites_to_view_model_factory()
        {
            // Given
            _target = GetTarget();
            _target.TempData["selectedResponsibilities"] = _selectedResponsibilityIds;

            // When
            var result = _target.GenerateResponsibilities(string.Join(",", _selectedResponsibilityIds));

            // Then
            _generateResponsibilitiesViewModelFactory.Verify(x => x.WithAllowedSiteIds(_allowedSites));
        }
        public void Given_array_of_responsibility_ids_When_GenerateResponsibilities_Then_pass_current_users_companyId_to_view_model_factory()
        {
            // Given
            _target = GetTarget();
            _target.TempData["selectedResponsibilities"] = _selectedResponsibilityIds;

            // When
            var result = _target.GenerateResponsibilities(string.Join(",", _selectedResponsibilityIds));

            // Then
            _generateResponsibilitiesViewModelFactory.Verify(x => x.WithCompanyId(TestControllerHelpers.CompanyIdAssigned));
        }
        public void Given_valid_model_When_GenerateResponsibilities_Then_map_responsibility_details_to_save_request()
        {
            // Given
            CreateResponsibilityFromWizardRequest passedCreateResponsibilityFromWizardRequest = null;
            _responsibilitiesService
                .Setup(x => x.CreateResponsibilitiesFromWizard(It.IsAny<CreateResponsibilityFromWizardRequest>()))
                .Callback<CreateResponsibilityFromWizardRequest>(y => passedCreateResponsibilityFromWizardRequest = y);
            _target = GetTarget();

            // When
            _target.GenerateResponsibilities(_model);

            // Then
            var requestTemplateDetails = passedCreateResponsibilityFromWizardRequest.ResponsibilityFromTemplateDetails;

            Assert.That(requestTemplateDetails, Is.InstanceOf<List<ResponsibilityFromTemplateDetail>>());

            for (var i = 0; i < _model.Responsibilities.Count(); i++)
            {
                Assert.That(requestTemplateDetails[i].ResponsibilityTemplateId, Is.EqualTo(_model.Responsibilities.ElementAt(i).ResponsibilityTemplateId));
                Assert.That(requestTemplateDetails[i].FrequencyId, Is.EqualTo(_model.Responsibilities.ElementAt(i).FrequencyId));
                Assert.That(requestTemplateDetails[i].ResponsiblePersonEmployeeId, Is.EqualTo(_model.Responsibilities.ElementAt(i).ResponsiblePersonEmployeeId));
            }
        }
 private WizardController GetTarget()
 {
     var controller = new WizardController(null, null, null, _responsibilitiesService.Object, null, null);
     return TestControllerHelpers.AddUserToController(controller);
 }
 private WizardController GetTarget()
 {
     var controller = new WizardController(null,null, null, null, null, null);
     return TestControllerHelpers.AddUserToController(controller);
 }
        public void Given_valid_model_When_GenerateResponsibilities_Then_return_json_success_equals_true()
        {
            // Given
            _target = GetTarget();

            // When
            dynamic result = _target.GenerateResponsibilities(_model);

            // Then
            Assert.That(result.Data.Success, Is.True);
        }
 private WizardController GetTarget()
 {
     var controller = new WizardController(null, null, null, _responsibilitiesService.Object, _bus.Object, _businessSafeSessionManager.Object);
     return TestControllerHelpers.AddUserToController(controller);
 }
        public void Given_model_with_no_Responsibilities_When_GenerateResponsibilities_Then_add_error_to_modelstate()
        {
            // Given
            var modelWithNoResponsibilities = _model;
            modelWithNoResponsibilities.Responsibilities = new List<ConfiguredResponsibilityFromTemplate>();

            _target = GetTarget();

            // When
            _target.GenerateResponsibilities(modelWithNoResponsibilities);

            // Then
            Assert.That(_target.ModelState.IsValid, Is.False);
        }
        public void Given_model_with_null_Responsibilities_When_GenerateResponsibilities_Then_add_error_to_modelstate()
        {
            // Given
            var modelWithNoResponsibilities = _model;
            modelWithNoResponsibilities.Responsibilities = null;

            _target = GetTarget();

            // When
            _target.GenerateResponsibilities(modelWithNoResponsibilities);

            // Then
            Assert.That(_target.ModelState.IsValid, Is.False);
        }
        public void Given_model_with_no_siteids_When_GenerateResponsibilities_Then_add_error_to_modelstate()
        {
            // Given
            var modelWithNoSites = _model;
            modelWithNoSites.SiteIds = new long[0];

            _target = GetTarget();

            // When
            _target.GenerateResponsibilities(modelWithNoSites);

            // Then
            Assert.That(_target.ModelState.IsValid, Is.False);
        }
        public void Given_invalid_model_When_GenerateResponsibilities_Then_return_errors_in_json()
        {
            // Given
            _target = GetTarget();

            // When
            _target.ModelState.AddModelError("error", "an error 1");
            _target.ModelState.AddModelError("error", "an error 2");
            _target.ModelState.AddModelError("error", "an error 3");
            dynamic result = _target.GenerateResponsibilities(_model);

            // Then
            Assert.That(result.Data.Errors.Length, Is.EqualTo(3));
        }
        public void Given_invalid_model_When_GenerateResponsibilities_Then_return_json_success_equals_false()
        {
            // Given
            _target = GetTarget();

            // When
            _target.ModelState.AddModelError("error", "an error");
            dynamic result = _target.GenerateResponsibilities(_model);

            // Then
            Assert.That(result.Data.Success, Is.EqualTo("false"));
        }
        public void Given_no_responsibility_ids_When_GenerateResponsibilities_Then_pass_null_to_view_model_factory()
        {
            // Given
            _target = GetTarget();

            // When
            var result = _target.GenerateResponsibilities(string.Empty);

            // Then
            _generateResponsibilitiesViewModelFactory.Verify(x => x.WithResponsibilityTemplateIds(It.IsAny<long[]>()), Times.Never());
        }
        public void Given_model_with_Responsibilities_with_one_null_ResponsibilityTemplateId_and_two_null_FrequencyIds_When_GenerateResponsibilities_Then_add_two_messages_for_each()
        {
            // Given
            var modelWithNoResponsibilities = _model;
            modelWithNoResponsibilities.Responsibilities = new List<ConfiguredResponsibilityFromTemplate>()
                                                           {
                                                               new ConfiguredResponsibilityFromTemplate()
                                                               {
                                                                   FrequencyId = TaskReoccurringType.None,
                                                                   ResponsiblePersonEmployeeId = Guid.NewGuid(),
                                                                   ResponsibilityTemplateId = 345L
                                                               },
                                                               new ConfiguredResponsibilityFromTemplate()
                                                               {
                                                                   FrequencyId = TaskReoccurringType.None,
                                                                   ResponsiblePersonEmployeeId = Guid.NewGuid(),
                                                                   ResponsibilityTemplateId = default(long)
                                                               }
                                                           };

            _target = GetTarget();

            // When
            _target.GenerateResponsibilities(modelWithNoResponsibilities);

            // Then
            Assert.That(_target.ModelState.Values.First().Errors.Count(), Is.EqualTo(2));
        }