Ejemplo n.º 1
0
        public void CannotAddSameRoomTwiceInDatabase()
        {
            // Arrange Everything We Need For Our Unit Tests
            options = new DbContextOptionsBuilder <ApplicationDBContext>()
                      .UseInMemoryDatabase(databaseName: "TestRevatureHousingData")
                      .Options;
            testContext        = new ApplicationDBContext(options);
            dummyRoomsData     = new RoomDummyData();
            dummyRooms         = dummyRoomsData.RoomsList;
            testRoomRepository = new RoomRepository(testContext);
            testRoomController = new RoomsController(testRoomRepository);
            dummyConstantRoom  = new Room()
            {
                RoomID = 12728
            };
            //Arrange
            Room dummyRoom    = dummyConstantRoom;
            var  postResponse = testRoomController.PostRoom(dummyRoom);
            //Act
            var secondPostResponse = testRoomController.PostRoom(dummyRoom);
            var secondPostResult   = secondPostResponse.Result.Result;
            var postStatusCode     = (secondPostResult as StatusCodeResult);

            //Assert
            Assert.IsInstanceOfType(secondPostResult, typeof(StatusCodeResult));
            Assert.AreEqual(postStatusCode.StatusCode, 409);
            // Clearing Changes
            ClearAllChanges();
        }
Ejemplo n.º 2
0
        public void CanDeleteRoomInDatabase()
        {
            // Arrange Everything We Need For Our Unit Tests
            options = new DbContextOptionsBuilder <ApplicationDBContext>()
                      .UseInMemoryDatabase(databaseName: "TestRevatureHousingData")
                      .Options;
            testContext        = new ApplicationDBContext(options);
            dummyRoomsData     = new RoomDummyData();
            dummyRooms         = dummyRoomsData.RoomsList;
            testRoomRepository = new RoomRepository(testContext);
            testRoomController = new RoomsController(testRoomRepository);
            dummyConstantRoom  = new Room()
            {
                RoomID = 12728
            };
            //Arrange
            Room room = new Room()
            {
                RoomID = 5
            };
            var postResponse = testRoomController.PostRoom(room);
            //Act
            var deleteResult     = testRoomController.DeleteRoom(5).Result.Result;
            var deleteStatusCode = (deleteResult as StatusCodeResult);

            //Assert
            Assert.AreEqual(deleteStatusCode.StatusCode, 202);
            // Clearing Changes
            ClearAllChanges();
        }
Ejemplo n.º 3
0
        public void CannotUpdateRoomWithWrongSignature()
        {
            // Arrange Everything We Need For Our Unit Tests
            options = new DbContextOptionsBuilder <ApplicationDBContext>()
                      .UseInMemoryDatabase(databaseName: "TestRevatureHousingData")
                      .Options;
            testContext        = new ApplicationDBContext(options);
            dummyRoomsData     = new RoomDummyData();
            dummyRooms         = dummyRoomsData.RoomsList;
            testRoomRepository = new RoomRepository(testContext);
            testRoomController = new RoomsController(testRoomRepository);
            dummyConstantRoom  = new Room()
            {
                RoomID = 12728
            };
            //Arrange
            Room room = new Room()
            {
                RoomID = 5
            };
            var postResponse = testRoomController.PostRoom(room);
            //Act
            var putResponse = testRoomController.PutRoom(128923, room).Result;

            //Assert
            Assert.IsInstanceOfType(putResponse, typeof(BadRequestResult));
            // Clearing Changes
            ClearAllChanges();
        }
Ejemplo n.º 4
0
 public void Populate()
 {
     foreach (Room room in dummyRooms)
     {
         var postResponse = testRoomController.PostRoom(room);
         var result       = postResponse.Result;
     }
 }
        public void Should_PostRoom()
        {
            Room testRoom = new Room {
                Id = 1, Name = "Test5", Description = "Test", VenueId = 1, Columns = 10, Rows = 10, Isles = "{}"
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Rooms.Create(testRoom)).Returns(true);

            RoomsController controller = new RoomsController(mock.Object);
            var             rooms      = controller.PostRoom(testRoom);

            Assert.IsType <CreatedAtActionResult>(rooms);
        }
Ejemplo n.º 6
0
        public async void Can_post_items()
        {
            using (_context)
            {
                var controller = new RoomsController(_context);

                Models.Room testdata = new Models.Room();
                testdata.roomName = "testroom";
                await controller.PostRoom(testdata);


                var room = controller.GetRoom();

                var List      = new List <Room>();
                int Listcount = 0;
                foreach (Room data1 in room.Result.Value.ToList())
                {
                    List.Add(data1);
                    Listcount++;
                }

                Assert.AreEqual(Listcount, List.Count);
                Assert.AreEqual("testroom", List[Listcount - 1].roomName);

                //Delete

                if (List.Count > 0)
                {
                    var item = List[List.Count - 1];

                    await controller.DeleteRoom(item.roomID);
                }

                room = controller.GetRoom();
                List = new List <Room>();

                foreach (Room data1 in room.Result.Value.ToList())
                {
                    List.Add(data1);
                }


                Assert.AreEqual(Listcount - 1, List.Count);
            }
        }
        public void ShouldNot_PostRoom_ModelStateError()
        {
            Room testRoom = new Room {
                Id = 1, Name = "Test5", Description = "Test", VenueId = 1, Columns = 10, Rows = 10, Isles = "{}"
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Rooms.Create(testRoom)).Returns(true);
            mock.Setup(f => f.Rooms.GetById(1)).Returns(testRoom);

            RoomsController controller = new RoomsController(mock.Object);

            controller.ModelState.AddModelError("TestError", "Error");
            var rooms = controller.PostRoom(testRoom);

            Assert.IsType <BadRequestObjectResult>(rooms);
        }