public void LocationsController_Create_Post_Invalid_Model_Should_Send_Back_For_Edit() { // Arrange var mock = new Mock <LocationsBackend>(context); var controller = new LocationsController(context, mock.Object); // Get mock data as view model var dataMock = new LocationsDataMock(); var dataRaw = dataMock.GetAllViewModelList()[0]; var data = new AllTablesViewModel(dataRaw); // Make ModelState Invalid controller.ModelState.AddModelError("test", "test"); // Act var result = controller.Create(data) as ViewResult; // Assert Assert.IsNotNull(result); Assert.AreEqual("Create Post", result.ViewName); }
public void AllTablesViewModel_ConvertBooleanEnumToString_Parameter_No_Should_Pass() { // Arrange var mockData = new LocationsDataMock(); var location = mockData.GetAllViewModelList()[0]; var viewModel = new AllTablesViewModel(); var viewModelProperties = typeof(AllTablesViewModel).GetProperties(); var specialQualitiesPropertyNameList = new List <string>(); foreach (var property in typeof(SpecialQualities).GetProperties()) { if (property.Name.Equals("LocationId") || property.Name.Equals("AccessNotes") || property.Name.Equals("InstallationType") || property.Name.Equals("Location") || property.Name.Equals("CoinStar") || property.Name.Equals("TellerServices") || property.Name.Equals("_24hourExpressBox") || property.Name.Equals("PartnerCreditUnion") || property.Name.Equals("MemberConsultant") || property.Name.Equals("InstantDebitCardReplacement")) { continue; } specialQualitiesPropertyNameList.Add(property.Name); } foreach (var property in viewModelProperties) { if (!specialQualitiesPropertyNameList.Contains(property.Name)) { continue; } property.SetValue(viewModel, BooleanEnum.N); } // Act var result = AllTablesViewModel.GetNewSpecialQualities(viewModel); // Assert foreach (var property in typeof(SpecialQualities).GetProperties()) { if (specialQualitiesPropertyNameList.Contains(property.Name)) { Assert.AreEqual("N", property.GetValue(result)); } } }
public void AllTablesViewModel_InstantiateViewModelropertiesWithOneLocation_Null_Parameter_Should_Pass() { // Arrange var viewModel = new AllTablesViewModel(); var mockData = new LocationsDataMock(); viewModel.locations = mockData.GetAllViewModelList(); // Act var result = viewModel.InstatiateViewModelPropertiesWithOneLocation(); // Assert Assert.IsTrue(result); }
public void AllTablesViewModel_ConvertStringToBooleanEnum_Parameter_Yes_Should_Pass() { // Arrange var mockData = new LocationsDataMock(); var location = mockData.GetAllViewModelList()[0]; var viewModel = new AllTablesViewModel(); var properties = typeof(SpecialQualities).GetProperties(); // All properties of DailyHours is null by default var specialQualitiesPropertyNameList = new List <string>(); foreach (var property in properties) { if (property.Name.Equals("LocationId") || property.Name.Equals("AccessNotes") || property.Name.Equals("InstallationType") || property.Name.Equals("Location") || property.Name.Equals("CoinStar") || property.Name.Equals("TellerServices") || property.Name.Equals("_24hourExpressBox") || property.Name.Equals("PartnerCreditUnion") || property.Name.Equals("MemberConsultant") || property.Name.Equals("InstantDebitCardReplacement")) { continue; } property.SetValue(location.SpecialQualities, "Y"); specialQualitiesPropertyNameList.Add(property.Name); } // Act viewModel.InstatiateViewModelPropertiesWithOneLocation(location); // Assert properties = typeof(AllTablesViewModel).GetProperties(); foreach (var property in properties) { if (!specialQualitiesPropertyNameList.Contains(property.Name)) { continue; } Assert.AreEqual(BooleanEnum.Y, property.GetValue(viewModel)); } }
public void AllTablesViewModel_ConvertStringToBooleanEnum_Parameter_Null_Should_Pass() { // Arrange var mockData = new LocationsDataMock(); var location = mockData.GetAllViewModelList()[0]; var viewModel = new AllTablesViewModel(); var properties = typeof(SpecialQualities).GetProperties(); // All properties of DailyHours is null by default var specialQualitiesPropertyNameList = new List <string>(); foreach (var property in properties) { if (property.Name.Equals("LocationId") || property.Name.Equals("Location")) { continue; } property.SetValue(location.SpecialQualities, null); specialQualitiesPropertyNameList.Add(property.Name); } // Act viewModel.InstatiateViewModelPropertiesWithOneLocation(location); // Assert properties = typeof(AllTablesViewModel).GetProperties(); foreach (var property in properties) { if (specialQualitiesPropertyNameList.Contains(property.Name)) { if (property.Name.Equals("InstallationType") || property.Name.Equals("AccessNotes")) { continue; } Assert.AreEqual(BooleanEnum.NULL, property.GetValue(viewModel)); } } }
public void LocationsController_Create_Post_Valid_Model_Should_Pass() { // Arrange var mock = new Mock <LocationsBackend>(context); mock.Setup(backend => backend.Create(It.IsAny <AllTablesViewModel>())).Returns(true); var controller = new LocationsController(context, mock.Object); // Get mock data as view model var dataMock = new LocationsDataMock(); var dataRaw = dataMock.GetAllViewModelList()[0]; var data = new AllTablesViewModel(dataRaw); // Act var result = controller.Create(data) as RedirectToActionResult; // Assert Assert.IsNotNull(result); Assert.AreEqual("Index", result.ActionName); }
public void LocationsController_Index_Get_Default_Should_Pass() { // Arrange var dataMock = new LocationsDataMock(); var backendMock = new Mock <LocationsBackend>(context); backendMock.Setup(backend => backend.IndexAsync(false)).Returns(Task.FromResult(dataMock.GetAllViewModelList())); var myController = new LocationsController(context, backendMock.Object); // Act var result = myController.Index(); // Assert Assert.IsNotNull(result); }