Example #1
0
        public void GetBookedTableShould_ReturnCorrectResult()
        {
            var repositoryMock = new Mock <IRepository <BookedTables> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IBookedTablesFactory>();

            var id          = Guid.NewGuid();
            var bookedTable = new BookedTables()
            {
                BookingId = id
            };
            var list = new List <BookedTables>()
            {
                bookedTable
            };

            repositoryMock.Setup(r => r.All).Returns(list.AsQueryable());

            var service = new Services.BookedTablesService(repositoryMock.Object,
                                                           unitOfWorkMock.Object, factoryMock.Object);

            var result = service.GetBookedTable(id);

            Assert.AreSame(bookedTable, result);
        }
Example #2
0
        public void ConstructorShould_SetPassedDataCorrectlly_WhenDataIsNotNull()
        {
            var repositoryMock = new Mock <IRepository <BookedTables> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IBookedTablesFactory>();

            var service = new Services.BookedTablesService(repositoryMock.Object,
                                                           unitOfWorkMock.Object, factoryMock.Object);

            Assert.IsNotNull(service);
        }
Example #3
0
        public void RemoveBookedTablesShould_CallRepositoryPropertyAll(string bookingId)
        {
            var repositoryMock = new Mock <IRepository <BookedTables> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IBookedTablesFactory>();

            var bookingIdGuid = new Guid(bookingId);
            var service       = new Services.BookedTablesService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object);

            service.RemoveBookedTables(bookingIdGuid);

            repositoryMock.Verify(r => r.All, Times.Once);
        }
Example #4
0
        public void GetBookedTableShould_CallRepositoryMethodAll()
        {
            var repositoryMock = new Mock <IRepository <BookedTables> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IBookedTablesFactory>();

            var service = new Services.BookedTablesService(repositoryMock.Object,
                                                           unitOfWorkMock.Object, factoryMock.Object);
            var id = Guid.NewGuid();

            service.GetBookedTable(id);

            repositoryMock.Verify(r => r.All, Times.Once);
        }
Example #5
0
        public void AddBookedTablesShould_CallFactoryMethodCreateBooking(int tablesCount)
        {
            var repositoryMock = new Mock <IRepository <BookedTables> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IBookedTablesFactory>();

            var service = new Services.BookedTablesService(repositoryMock.Object,
                                                           unitOfWorkMock.Object, factoryMock.Object);

            var bookingId = Guid.NewGuid();
            var tableId   = Guid.NewGuid();

            service.AddBookedTables(bookingId, tableId, tablesCount);

            factoryMock.Verify(f => f.CreateBookedTable(bookingId, tableId, tablesCount));
        }
Example #6
0
        public void CreateBookingShould_CallRepositoryMethodAdd(int tablesCount)
        {
            var repositoryMock = new Mock <IRepository <BookedTables> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IBookedTablesFactory>();

            var service = new Services.BookedTablesService(repositoryMock.Object,
                                                           unitOfWorkMock.Object, factoryMock.Object);

            var bookingId   = Guid.NewGuid();
            var tableId     = Guid.NewGuid();
            var bookedTable = new BookedTables()
            {
                BookingId   = bookingId,
                TableId     = tableId,
                TablesCount = tablesCount
            };

            factoryMock.Setup(f => f.CreateBookedTable(bookingId, tableId, tablesCount)).Returns(bookedTable);
            service.AddBookedTables(bookingId, tableId, tablesCount);

            repositoryMock.Verify(r => r.Add(bookedTable), Times.Once);
        }
Example #7
0
        public void RemoveBookedTablesShould_CallUnitOfWorkMethodCommitForEachBooking(string bookingId)
        {
            var repositoryMock = new Mock <IRepository <BookedTables> >();
            var unitOfWorkMock = new Mock <IUnitOfWork>();
            var factoryMock    = new Mock <IBookedTablesFactory>();

            var bookingIdGuid = new Guid(bookingId);
            var bookedTable   = new BookedTables()
            {
                BookingId = bookingIdGuid
            };
            var list = new List <BookedTables>()
            {
                bookedTable
            };

            repositoryMock.Setup(r => r.All).Returns(list.AsQueryable());

            var service = new Services.BookedTablesService(repositoryMock.Object, unitOfWorkMock.Object, factoryMock.Object);

            service.RemoveBookedTables(bookingIdGuid);

            unitOfWorkMock.Verify(r => r.Commit(), Times.Once);
        }