예제 #1
0
        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);
        }
예제 #2
0
        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 LocationsDataMock_StringsAreEqual_Params_Are_Null_Should_Pass()
        {
            // Arrange
            var dataMock = new LocationsDataMock();


            // Act
            var result = dataMock.StringsAreEqual(null, null);


            // Assert
            Assert.IsTrue(result);
        }
        public void LocationsDataMock_Constructor_Should_Pass()
        {
            // Arrange


            // Act
            var dataMock = new LocationsDataMock();



            // Assert
            Assert.IsNotNull(dataMock);
        }
예제 #5
0
        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 LocationsDataMock_GetOneLocation_WhereClause_Param_Is_Null_Should_Pass()
        {
            // Arrange
            var dataMock = new LocationsDataMock();


            // Act
            var result = dataMock.GetOneLocation(null);


            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.LocationId, "a91be80e-ed05-4157-bb95-aa3494663d2a");
        }
        public void LocationsDataMock_StringsAreEqual_One_Param_Is_Null_Should_Pass()
        {
            // Arrange
            var dataMock = new LocationsDataMock();


            // Act
            var result1 = dataMock.StringsAreEqual(null, "test");
            var result2 = dataMock.StringsAreEqual("test", null);


            // Assert
            Assert.IsFalse(result1);
            Assert.IsFalse(result2);
        }
예제 #8
0
        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));
            }
        }
예제 #9
0
        public void Locations_Create_Get_Default_Should_Pass()
        {
            // Arrange
            var mock         = new Mock <LocationsBackend>(context);
            var dataMock     = new LocationsDataMock();
            var myController = new LocationsController(context, mock.Object);



            // Act
            var result = myController.Create();



            // Assert
            Assert.IsNotNull(result);
        }
예제 #10
0
        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);
        }
        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));
                }
            }
        }
예제 #12
0
        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);
        }