Пример #1
0
 public void DeleteConfirmed_WhenIdIsLargerThanZero_RemoveIsCalled()
 {
     // Act
     controller.DeleteConfirmed(1);
     // Assert against the mock object
     fakeRoomRepository.Verify(x => x.Remove(It.IsAny <int>()));
 }
        public void DeleteConfirmed_WhenIdIsLargerThan1000_RemoveThrowsException()
        {
            // Arrange
            IRepository <Room> fakeRoomRepos = Substitute.For <IRepository <Room> >();

            fakeRoomRepos.When(repos => repos.Remove(Arg.Is <int>(id => id > 1000))).
            Do(context => { throw new Exception("Room id cannot be larger than 1000"); });
            RoomsController controller = new RoomsController(fakeRoomRepos);

            // Assert
            Assert.Throws <Exception>(() => controller.DeleteConfirmed(1001));
        }
        //[Ignore]
        public void DeleteConfirmed_WhenIdIsLessThanOne_RemoveIsNotCalled()
        {
            // Arrange
            IRepository <Room> fakeRoomRepos = Substitute.For <IRepository <Room> >();
            RoomsController    controller    = new RoomsController(fakeRoomRepos);
            int id = 0;

            // Act
            controller.DeleteConfirmed(id);

            // Assert
            fakeRoomRepos.DidNotReceive().Remove(id);
        }
        public void DeleteConfirmed_WhenIdIsLargerThanZero_RemoveIsCalled()
        {
            // Arrange

            // Create a mock object
            IRepository <Room> fakeRoomRepos = Substitute.For <IRepository <Room> >();

            // Create RoomsController instance and inject the fake RoomRepository
            RoomsController controller = new RoomsController(fakeRoomRepos);
            int             id         = 1;

            // Act
            controller.DeleteConfirmed(id);

            // Assert
            // Assert against the mock object
            fakeRoomRepos.Received().Remove(id);
        }