public void GivenLogicManagerCreatesViewModel_WhenCreate_ThenPartialViewContainsViewModel() { var expected = new PublicFieldModel(); MockLogicManager.Expect(m => m.GenerateCreateViewModel()).Return(expected); PartialViewResult result = Target.Create(); result.AssertGetViewModel(expected); }
public void GivenModelIsForPublicFieldWithPublicData_AndDataTypeIsChanged_WhenIPostEdit_ThenReturnEditView() { var expected = new PublicFieldModel(); MockLogicManager.Expect(m => m.Edit(expected, User)).Throw(new ValidationException(new ValidationResult("Error!"), null, expected)); PartialViewResult result = Target.Edit(expected) as PartialViewResult; result.AssertGetViewModel(expected); }
public void GivenModelIsForPublicFieldWithPublicData_AndDataTypeIsChanged_WhenIPostEdit_ThenViewModelPopulated() { var expected = new PublicFieldModel(); MockLogicManager.Expect(m => m.Edit(expected, User)).Throw(new ValidationException(new ValidationResult("Error!"), null, expected)); Target.Edit(expected); MockLogicManager.AssertWasCalled(m => m.PopulateViewModel(expected)); }
public void GivenValidateThrowValidationException_WhenIPostEdit_ThenReturnCreateViewWithViewModel() { var viewModel = new PublicFieldModel(); MockLogicManager.Expect(m => m.Validate(viewModel)).Throw(new ValidationException(new ValidationResult("blah", new[] { "FieldNameWithError" }), null, viewModel)); var result = Target.Edit(viewModel) as PartialViewResult; result.AssertGetViewModel(viewModel); }
public void GivenAnInvalidSelectedCategory_WhenCreate_ThenSaveIsCalled() { var viewModel = new PublicFieldModel { FieldName = "Test", SelectedFieldTypeId = 1, SelectedCategories = new List<int> { 1, 100 } }; Target.ExpectException<EntityNotFoundException>(() => Target.Create(viewModel, User)); }
public void GivenValidationExceptionThrown_WhenIPostDelete_ThenReturnDeleteView() { CustomFieldModel expected = new PublicFieldModel(); MockLogicManager.Expect(m => m.Delete(1)).Throw(new ValidationException(new ValidationResult("blah"), null, 1)); MockLogicManager.Expect(m => m.GenerateDeleteViewModel(1)).Return(expected); var result = Target.DeleteConfirmed(1) as PartialViewResult; result.AssertGetViewModel(expected); }
public void GivenValidationExceptionThrown_WhenIPostDelete_ThenModelStateContainsError() { CustomFieldModel expected = new PublicFieldModel(); MockLogicManager.Expect(m => m.Delete(1)).Throw(new ValidationException(new ValidationResult("blah"), null, 1)); MockLogicManager.Expect(m => m.GenerateDeleteViewModel(1)).Return(expected); Target.DeleteConfirmed(1); Assert.AreEqual("blah", Target.ModelState[string.Empty].Errors.Single().ErrorMessage); }
public void GivenModelIsForPublicFieldWithPublicData_AndDataTypeIsChanged_WhenIPostEdit_ThenModelStateHasError() { string expectedErrorMessage = "blah"; string expectedFieldName = "FieldNameWithError"; var viewModel = new PublicFieldModel(); MockLogicManager.Expect(m => m.Edit(viewModel, User)).Throw(new ValidationException(new ValidationResult(expectedErrorMessage, new[] { expectedFieldName }), null, viewModel)); Target.Edit(viewModel); Assert.IsTrue(Target.ModelState[expectedFieldName].Errors.Any(e => e.ErrorMessage == expectedErrorMessage)); }
public void GivenValidateThrowValidationException_WhenIPostEdit_ThenModelStateErrorIncludesMemberNameAndMessage() { string expectedErrorMessage = "blah"; string expectedFieldName = "FieldNameWithError"; var viewModel = new PublicFieldModel(); MockLogicManager.Expect(m => m.Validate(viewModel)).Throw(new ValidationException(new ValidationResult(expectedErrorMessage, new[] { expectedFieldName }), null, viewModel)); Target.Edit(viewModel); Assert.IsTrue(Target.ModelState[expectedFieldName].Errors.Any(e => e.ErrorMessage == expectedErrorMessage)); }
public void GivenModelNotModified_WhenCopyFrom_ThenModelStatelastModifyValuesNull() { CustomField expectedState = new PublicField { CreateTime = new DateTime(2005, 4, 30), CreatingUser = new User { DisplayName = "fredBob" } }; CustomFieldModel target = new PublicFieldModel(); target.CopyFrom(expectedState); Assert.IsNull(target.Audit.LastModifiedBy); Assert.IsFalse(target.Audit.LastModifyTime.HasValue); }
public void GivenModelHasAuditData_WhenCopyFrom_ThenModelStateSet() { CustomField expectedState = new PublicField { CreateTime = new DateTime(2005, 4, 30), CreatingUser = new User { DisplayName = "fredBob" }, LastModifyTime = new DateTime(2010, 5, 13), LastModifyingUser = new User { DisplayName = "jimGeorge" } }; CustomFieldModel target = new PublicFieldModel(); target.CopyFrom(expectedState); AuditModel actualState = target.Audit; Assert.AreEqual(expectedState.CreateTime, actualState.CreateTime); Assert.AreEqual(expectedState.CreatingUser.DisplayName, actualState.CreatedBy); Assert.AreEqual(expectedState.LastModifyTime, actualState.LastModifyTime); Assert.AreEqual(expectedState.LastModifyingUser.DisplayName, actualState.LastModifiedBy); }
public void GivenInvalidViewModel_WhenPopulateViewModel_ThenThrowException() { PublicFieldModel invalid = new PublicFieldModel(); Target.ExpectException <ArgumentException>(() => Target.PopulateViewModel(invalid)); }
public void GivenInvalidViewModel_WhenPopulateViewModel_ThenThrowException() { PublicFieldModel invalid = new PublicFieldModel(); Target.ExpectException<ArgumentException>(() => Target.PopulateViewModel(invalid)); }
public void GivenFieldNameDiffers_WhenValidate_ThenSucceed() { var viewModel = new PublicFieldModel { FieldName = "this is a new name" }; Target.Validate(viewModel); }
public void GivenAnInvalidModel_WhenEdit_ThenAnEntityNotFoundException() { var viewModel = new PublicFieldModel { Id = 45454 }; TestExtensions.ExpectException<EntityNotFoundException>(() => Target.Edit(viewModel, User)); }
public void GivenDuplicateFieldName_WhenValidate_ThenValidationExceptionMemberNamesIncludesFieldName() { var viewModel = new PublicFieldModel { FieldName = Repositories.MockCustomFieldRepository.Items.First().Name }; ValidationException actual = Target.ExpectException<ValidationException>(() => Target.Validate(viewModel)); Assert.IsTrue(actual.ValidationResult.MemberNames.Contains("FieldName")); }
public void WhenPopulateViewModel_ThenTheListsArePopulated() { var expectedCategories = Data.CustomFieldCategories; var expectedFieldTypes = Data.CustomFieldTypes; var viewModel = new PublicFieldModel(); Target.PopulateViewModel(viewModel); Assert.IsNotNull(viewModel.Categories); Assert.AreEqual("Id", viewModel.Categories.DataValueField); Assert.AreEqual("Name", viewModel.Categories.DataTextField); CollectionAssert.AreEqual(expectedCategories, viewModel.Categories.Items.Cast<CustomFieldCategory>().ToList()); Assert.IsNotNull(viewModel.FieldTypes); Assert.AreEqual("Id", viewModel.FieldTypes.DataValueField); Assert.AreEqual("Name", viewModel.FieldTypes.DataTextField); CollectionAssert.AreEqual(expectedFieldTypes, viewModel.FieldTypes.Items.Cast<CustomFieldType>().ToList()); }
public void WhenEdit_ThenEntityUpdated_AndChangesSaved() { int publicFieldId = 1; var publicField = Data.CustomFields.Single(c => c.Id == publicFieldId); var viewModel = new PublicFieldModel { Id = publicFieldId, FieldName = "testing", SelectedFieldTypeId = 1 }; Target.Edit(viewModel, User); Repositories.MockCustomFieldRepository.AssertWasCalled(m => m.Update(publicField)); Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save()); }
public void WhenEdit_ThenEntityModifiedPropertiesSet() { int publicFieldId = 1; var publicField = Data.CustomFields.Single(c => c.Id == publicFieldId); var viewModel = new PublicFieldModel { Id = publicFieldId, SelectedFieldTypeId = publicField.CustomFieldTypeId }; Target.Edit(viewModel, User); Assert.IsTrue(publicField.LastModifyTime.Value.WithinTimeSpanOf(TimeSpan.FromSeconds(1), DateTime.Now)); Assert.AreEqual(User.Identity.User, publicField.LastModifyingUser); }
public void WhenCreate_ThenSaveIsCalled() { var viewModel = new PublicFieldModel { FieldName = "Test", SelectedFieldTypeId = 1, SelectedCategories = new List<int> { 1, 2 } }; Target.Create(viewModel, User); Repositories.MockRepositoryContainer.AssertWasCalled(m => m.Save()); }
public void GivenDuplicateFieldName_WhenValidate_ThenThrowValidationException() { var viewModel = new PublicFieldModel { FieldName = Repositories.MockCustomFieldRepository.Items.First().Name }; Target.ExpectException<ValidationException>(() => Target.Validate(viewModel)); }
public void GivenDuplicateFieldName_AndIdMatches_WhenValidate_ThenSucceed() { var viewModel = new PublicFieldModel { FieldName = Repositories.MockCustomFieldRepository.Items.First().Name, Id = Repositories.MockCustomFieldRepository.Items.First().Id }; Target.Validate(viewModel); }
public void GivenNullUser_WhenCreate_ThenAnArgumentNullExceptionIsThrown() { var viewModel = new PublicFieldModel(); TestExtensions.ExpectException<ArgumentNullException>(() => Target.Create(viewModel, null)); }
public void GivenNullUser_WhenEdit_ThenThrowException() { var viewModel = new PublicFieldModel { Id = 45454 }; Target.ExpectException<ArgumentNullException>(() => Target.Edit(viewModel, null)); }
public void GivenPublicFieldViewModel_AndPublicFieldHasNoValues_AndServiceTypeIsDifferent_WhenEdit_ThenSucceed() { var viewModel = new PublicFieldModel { Id = 4, SelectedFieldTypeId = 1 }; Target.Edit(viewModel, User); }
public void GivenPublicFieldViewModel_AndPublicFieldHasValues_AndServiceTypeIsDifferent_WhenEdit_ThenThrowValidationException_AndValidationExceptionIsForSelectedFieldTypeId() { var viewModel = new PublicFieldModel { Id = 1, SelectedFieldTypeId = 2 }; ValidationException actual = Target.ExpectException<ValidationException>(() => Target.Edit(viewModel, User)); CollectionAssert.Contains(actual.ValidationResult.MemberNames.ToList(), "SelectedFieldTypeId"); }
private static bool AssertPropertiesMatch(PublicFieldModel expectedState, PublicField actualState) { Assert.IsNotNull(actualState); Assert.AreEqual(expectedState.FieldName, actualState.Name); Assert.AreEqual(expectedState.SelectedFieldTypeId, actualState.CustomFieldTypeId); CollectionAssert.AreEqual(expectedState.SelectedCategories.ToList(), actualState.Categories.Select(c => c.Id).ToList()); return true; }
public void WhenCreate_ThenPublicFieldAddedWithCorrectState() { var viewModel = new PublicFieldModel { FieldName = "Test", SelectedFieldTypeId = 1, SelectedCategories = new List<int> { 1, 2 } }; Target.Create(viewModel, User); Repositories.MockCustomFieldRepository.AssertWasCalled(m => m.Add(Arg<PublicField>.Matches(c => AssertPropertiesMatch(viewModel, c)))); }