public void TestForCreate()
        {
            //Arrange
            //Act
            ViewResult result = (ViewResult)controller.Create();

            //Assert.Same(result.Model, typeof(List<Location>));
            Assert.NotNull(result);
            //Assert.Equal("1","Saket");
        }
        public void CreateTest()
        {
            PartialViewResult rv = (PartialViewResult)_controller.Create();

            Assert.IsInstanceOfType(rv.Model, typeof(LocationVM));

            LocationVM vm = rv.Model as LocationVM;
            Location   v  = new Location();

            v.Name    = "bhVtNC";
            vm.Entity = v;
            _controller.Create(vm);

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Location>().FirstOrDefault();

                Assert.AreEqual(data.Name, "bhVtNC");
            }
        }
예제 #3
0
        public async Task LOC01_CreateLocationTest()
        {
            // Arrange
            Guid id = Guid.NewGuid();

            // Act
            _location = await LocationController.Create(_authToken, "TestLocation" + id.ToString(), "Test Location");

            _objectsToCleanup.Add(_location);

            // Assert
            Assert.IsNotNull(_location, "Failed to create a new Location");
            Assert.IsTrue(_location.IsActive, "Location.IsActive evaluated to false");
        }
예제 #4
0
        public void CreateGet_View_True()
        {
            // Arrange - create the controller
            LocationController    target        = new LocationController(mock.Object);
            IEnumerable <Country> countriesList = from c in mock.Object.Countries
                                                  orderby c.CountryName
                                                  select c;

            // Act - call the action method
            var result = target.Create() as ViewResult;

            // Assert - check the result
            Assert.AreEqual(countriesList.ToList(), ((ViewResult)result).ViewBag.CountryList.Items);
            Assert.AreEqual("", result.ViewName);
        }
예제 #5
0
        public async Task LOC06_SetLocationParentCommitTest()
        {
            // Arrange
            Guid     testId = Guid.NewGuid();
            Location parent = await LocationController.Create(_authToken, "TestParentLocation" + testId.ToString(), "Test Parent Location");

            _objectsToCleanup.Add(parent);
            _location.Parent = parent;

            // Act
            await _location.Commit(_authToken);

            // Assert
            Assert.AreEqual(parent, _location.Parent, "Location.Parent does not match the test data");
        }
        public async Task HWA09_SetHardwareAssetLocationCommitTest()
        {
            // Arrange
            Guid     testId = Guid.NewGuid();
            Location loc    = await LocationController.Create(_authToken, testId.ToString(), testId.ToString());

            _objectsToCleanup.Add(loc);
            _asset.Location = loc;

            // Act
            await _asset.Commit(_authToken);

            // Assert
            Assert.AreEqual(loc, _asset.Location, "HardwareAsset.Location does not match the test data");
        }
예제 #7
0
        public void CreatePost_CanCreate_ValidLocationNullResponsibleID()
        {
            // Arrange - create the controller
            LocationController target   = new LocationController(mock.Object);
            Location           location = new Location {
                LocationID = 1, Title = "LDF", Address = "Kyiv, Shevchenka St."
            };

            // Act - call the action method
            RedirectToRouteResult result = (RedirectToRouteResult)target.Create(location);

            // Assert - check the result
            mock.Verify(m => m.SaveLocation(location), Times.Once);
            Assert.IsFalse(result.Permanent);
            Assert.AreEqual("Home", result.RouteValues["controller"]);
            Assert.AreEqual("PUView", result.RouteValues["action"]);
        }
예제 #8
0
        public void CreatePost_CannotCreate_InvalidResponsibleID()
        {
            // Arrange - create the controller
            Location location = new Location {
                LocationID = 1, Title = "LDF", Address = "Kyiv, Shevchenka St.", ResponsibleForLoc = "dan"
            };
            LocationController target = new LocationController(mock.Object);

            // Act - call the action method
            var    result = target.Create(location);
            string data   = (string)(new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(((JsonResult)result).Data, "error")).Target;

            // Assert - check the result
            mock.Verify(m => m.SaveLocation(It.IsAny <Location>()), Times.Never);
            Assert.IsInstanceOf(typeof(JsonResult), result);
            Assert.AreEqual("Not existing Employee's EID", data);
        }
예제 #9
0
        public void CreatePost_CannotCreate_InvalidLocation()
        {
            // Arrange - create the controller
            Location              location      = new Location();
            LocationController    target        = new LocationController(mock.Object);
            IEnumerable <Country> countriesList = from c in mock.Object.Countries
                                                  orderby c.CountryName
                                                  select c;

            // Act - call the action method
            target.ModelState.AddModelError("error", "error");
            ViewResult result = target.Create(location) as ViewResult;

            // Assert - check the result
            mock.Verify(m => m.SaveLocation(It.IsAny <Location>()), Times.Never);
            Assert.AreEqual(countriesList.ToList(), ((ViewResult)result).ViewBag.CountryList.Items);
            Assert.IsInstanceOf(typeof(Location), result.ViewData.Model);
            Assert.IsInstanceOf(typeof(ViewResult), result);
        }
예제 #10
0
        public void GivenNavigatorShowCreateLocationView()
        {
            INavigationRepository repository = GenerateRepository();
            LocationController    target     = new LocationController(repository);
            Navigator             navigator  = GenerateNavigator();
            ActionResult          actual;

            actual = target.Create(navigator);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
            ViewResult result = actual as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
            TestViewResult(navigator, result);
            LocationViewModel model = result.Model as LocationViewModel;

            Assert.AreEqual(model.LocationId, 0);
            Assert.IsTrue(String.IsNullOrEmpty(model.LocationName));
        }
예제 #11
0
        public void GivenLocationViewModelCreateNewLocation()
        {
            INavigationRepository repository = GenerateRepository();
            LocationController    target     = new LocationController(repository);
            LocationViewModel     location   = Utilities.ObjectFactory.CreateLocation(GenerateNavigator());

            repository.Expect(r => r.SaveLocation(location)).Return(true);
            ActionResult actual;

            actual = target.Create(location);
            Assert.IsNotNull(actual);
            Assert.IsInstanceOfType(actual, typeof(RedirectToRouteResult));
            RedirectToRouteResult result = actual as RedirectToRouteResult;

            Assert.AreEqual("area_default", result.RouteName);
            Assert.AreEqual("Details", result.RouteValues["Action"]);
            Assert.AreEqual(location.RegionName, result.RouteValues["RegionName"]);
            Assert.AreEqual(location.AreaName, result.RouteValues["AreaName"]);
            repository.VerifyAllExpectations();
        }
예제 #12
0
        public async void Create_Errors()
        {
            LocationControllerMockFacade mock = new LocationControllerMockFacade();

            var mockResponse = new Mock <CreateResponse <ApiLocationServerResponseModel> >(null as ApiLocationServerResponseModel);
            var mockRecord   = new ApiLocationServerResponseModel();

            mockResponse.SetupGet(x => x.Success).Returns(false);

            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiLocationServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiLocationServerResponseModel> >(mockResponse.Object));
            LocationController controller = new LocationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiLocationServerRequestModel());

            response.Should().BeOfType <ObjectResult>();
            (response as ObjectResult).StatusCode.Should().Be((int)HttpStatusCode.UnprocessableEntity);
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiLocationServerRequestModel>()));
        }
예제 #13
0
        public async void Create_No_Errors()
        {
            LocationControllerMockFacade mock = new LocationControllerMockFacade();

            var mockResponse = ValidationResponseFactory <ApiLocationServerResponseModel> .CreateResponse(null as ApiLocationServerResponseModel);

            mockResponse.SetRecord(new ApiLocationServerResponseModel());
            mock.ServiceMock.Setup(x => x.Create(It.IsAny <ApiLocationServerRequestModel>())).Returns(Task.FromResult <CreateResponse <ApiLocationServerResponseModel> >(mockResponse));
            LocationController controller = new LocationController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Create(new ApiLocationServerRequestModel());

            response.Should().BeOfType <CreatedResult>();
            (response as CreatedResult).StatusCode.Should().Be((int)HttpStatusCode.Created);
            var createResponse = (response as CreatedResult).Value as CreateResponse <ApiLocationServerResponseModel>;

            createResponse.Record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Create(It.IsAny <ApiLocationServerRequestModel>()));
        }
예제 #14
0
        public async Task LOC08_SetLocationChildrenCommitTest()
        {
            // Arrange
            Guid     testId         = Guid.NewGuid();
            Location childLocation1 = await LocationController.Create(_authToken, "TestChildLocation1" + testId.ToString(), "Test Child Location 1");

            Location childLocation2 = await LocationController.Create(_authToken, "TestChildLocation2" + testId.ToString(), "Test Child Location 2");

            _objectsToCleanup.Add(childLocation1);
            _objectsToCleanup.Add(childLocation2);

            _location.Children.Add(childLocation1);
            _location.Children.Add(childLocation2);

            // Act
            await _location.Commit(_authToken);

            // Assert
            Assert.AreEqual(2, _location.Children.Count, "Expected 2 Location.Children, got " + _location.Children.Count);
            Assert.IsTrue(_location.Children.Contains(childLocation1), "Location.Children does not contain the first test child");
            Assert.IsTrue(_location.Children.Contains(childLocation2), "Location.Children does not contain the second test child");
        }
예제 #15
0
        public void Store2()
        {
            // ARRANGE
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock
            .Protected()
            // Setup the PROTECTED method to mock
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            // prepare the expected response of the mocked http call
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = null,
            })
            .Verifiable();

            var httpClient = new HttpClient(handlerMock.Object)
            {
                BaseAddress = new Uri("http://test.com/"),
            };
            var subjectUnderTest = new EquipmentController(httpClient, new Web.MyConfiguration()
            {
                ServiceUrl = "http://test.com/"
            });

            var result  = subjectUnderTest.Index();
            var result2 = subjectUnderTest.Create();
            var result3 = subjectUnderTest.Create(new EquipmentModel());
            var result4 = subjectUnderTest.Edit(new EquipmentModel());
            var result5 = subjectUnderTest.Edit(1, 2, "", "", 2, 3, 3);

            var subjectUnderTest2 = new LocationController(httpClient, new Web.MyConfiguration()
            {
                ServiceUrl = "http://test.com/"
            });
            var result6  = subjectUnderTest2.Index();
            var result7  = subjectUnderTest2.Create();
            var result8  = subjectUnderTest2.Create(new LocationModel());
            var result9  = subjectUnderTest2.EditLoot(1, 1, 1, "", 1, "");
            var result10 = subjectUnderTest2.EditLoot(new LootModel());
            var result11 = subjectUnderTest2.EditLocation(new LocationModel());
            var result12 = subjectUnderTest2.EditLocation(1, "", "", 1);
            var result13 = subjectUnderTest2.Delete(1);

            var subjectUnderTest3 = new HomeController();

            subjectUnderTest3.Index();
            subjectUnderTest3.Privacy();


            var subjectUnderTest4 = new LootController(httpClient, new Web.MyConfiguration()
            {
                ServiceUrl = "http://test.com/"
            });
            var result17          = subjectUnderTest4.Index();
            var subjectUnderTest5 = new PlayerController(httpClient, new Web.MyConfiguration()
            {
                ServiceUrl = "http://test.com/"
            });
            var result18 = subjectUnderTest5.Index();
            var result19 = subjectUnderTest5.Edit(1, 2, "", "", 1, 1);
            var result20 = subjectUnderTest5.Edit(new LootModel());
            var result21 = subjectUnderTest5.EditPlayer(1, "", 1);
            var result22 = subjectUnderTest5.EditPlayer(new PlayerModel());
            var result23 = subjectUnderTest5.EditEquipment(1, 1, "", "", 1, 1, 1);
            var result24 = subjectUnderTest5.EditEquipment(new EquipmentModel());
            var result25 = subjectUnderTest5.Delete(1, new LootModel());
            var result26 = subjectUnderTest5.Delete(1);
            var result27 = subjectUnderTest5.DeleteEquipment(1, new EquipmentModel());

            Assert.NotNull(subjectUnderTest);
        }
        public void Create_AddOneStore()
        {
            // tempo solution- a mix of old and new versions
            // arrange
            var _mockRepo  = new Mock <IStoreRepository>();
            var controller = new LocationController(_mockRepo.Object, new NullLogger <LocationController>());

            CStore store = null;

            _mockRepo.Setup(x => x.AddOneStore(It.IsAny <CStore>())).Callback <CStore>(x => store = x);

            var newLocation  = new CStore("Techland Paris 3", "7071231234", "85041");
            var viewLocation = new StoreViewModel
            {
                Storeloc   = newLocation.Storeloc,
                Storephone = newLocation.Storephone,
                Zipcode    = newLocation.Zipcode,
            };

            // act
            IActionResult actionResult = controller.Create(viewLocation);

            // assert
            Assert.True(controller.ModelState.IsValid);
            _mockRepo.Verify(r => r.AddOneStore(It.IsAny <CStore>()), Times.Once);
            Assert.Equal(viewLocation.Storeloc, store.Storeloc);
            Assert.Equal(viewLocation.Storephone, store.Storephone);
            Assert.Equal(viewLocation.Zipcode, store.Zipcode);
            Assert.IsAssignableFrom <RedirectToActionResult>(actionResult);

            /*
             * // old version that works
             * // arrange
             * var _mockRepo = new Mock<IStoreRepository>();
             * var controller = new LocationController(_mockRepo.Object, new NullLogger<LocationController>());
             *
             * var newLocation = new CStore("Techland Paris 3", "7071231234", "85041");
             * var viewLocation = new StoreViewModel
             * {
             *  Storeloc = newLocation.Storeloc,
             *  Storephone = newLocation.Storephone,
             *  Zipcode = newLocation.Zipcode,
             * };
             *
             * // act
             * IActionResult actionResult = controller.Create(viewLocation);
             *
             * // assert
             * Assert.True(controller.ModelState.IsValid);
             * var viewResult = Assert.IsAssignableFrom<RedirectToActionResult>(actionResult);
             */

            /*
             * // new version that does not work
             * mockStoreRepository.Setup(x => x.AddOneStore(It.IsAny<CStore>())).Verifiable();
             * IActionResult actionResult = controller.Create(It.IsAny<StoreViewModel>());
             * Assert.True(controller.ModelState.IsValid);
             * var viewResult = Assert.IsAssignableFrom<RedirectToActionResult>(actionResult);
             * mockStoreRepository.Verify(r => r.AddOneStore(It.IsAny<CStore>()), Times.Once);
             */
        }