Exemplo n.º 1
0
        public void ShouldSaveDeskBooking()
        {
            DeskBooking savedDeskBooking = null;

            _deskBookingRepositoryMock.Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(deskBooking =>
            {
                savedDeskBooking = deskBooking;
            });

            _processor.BookDesk(_request);

            _deskBookingRepositoryMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);

            using (new AssertionScope())
            {
                //Assert.NotNull(savedDeskBooking);
                savedDeskBooking.Should().NotBeNull();
                //Assert.Equal(_request.FirstName, savedDeskBooking.FirstName);
                savedDeskBooking.FirstName.Should().Be(_request.FirstName);
                //Assert.Equal(_request.LastName, savedDeskBooking.LastName);
                savedDeskBooking.LastName.Should().Be(_request.LastName);
                //Assert.Equal(_request.Email, savedDeskBooking.Email);
                savedDeskBooking.Email.Should().Be(_request.Email, because: "Email address must be correct");
                //Assert.Equal(_request.Date, savedDeskBooking.Date);
                savedDeskBooking.Date.Should().BeSameDateAs(_request.Date);
                //Assert.Equal(_availableDesks.First().Id, savedDeskBooking.DeskId);
                savedDeskBooking.DeskId.Should().Be(_availableDesks.First().Id);
            }
        }
        public void ShouldSaveDeskBooking()
        {
            //GIVEN
            DeskBooking savedDeskBooking = null;

            // this is basically to say that when Save gets called with a DeskBooking object, it should save it in
            // the variable savedDeskBooking.
            _deskBookingRepositoryMock.Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(deskBooking =>
            {
                savedDeskBooking = deskBooking;
            });

            //WHEN
            _processor.BookDesk(_request);

            //THEN

            //verify that the processor called the save method once when booking a desk.
            _deskBookingRepositoryMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);

            Assert.NotNull(savedDeskBooking);
            Assert.Equal(_request.FirstName, savedDeskBooking.FirstName);
            Assert.Equal(_request.LastName, savedDeskBooking.LastName);
            Assert.Equal(_request.Email, savedDeskBooking.Email);
            Assert.Equal(_request.Date, savedDeskBooking.Date);
            Assert.Equal(_availableDesks.First().Id, savedDeskBooking.DeskId);
        }
Exemplo n.º 3
0
        public void ShouldSaveDeskBooking()
        {
            //Arrange
            DeskBooking savedDeskBooking = null;

            //call dependencies
            //Act
            _deskBookingRepository.Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(deskBooking =>
            {
                savedDeskBooking = deskBooking;
            });

            _processor.BookDesk(_request);

            //Assert
            _deskBookingRepository.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);

            Assert.NotNull(savedDeskBooking);
            Assert.Equal(_request.FirstName, savedDeskBooking.FirstName);
            Assert.Equal(_request.LastName, savedDeskBooking.LastName);
            Assert.Equal(_request.Email, savedDeskBooking.Email);
            Assert.Equal(_request.Date, savedDeskBooking.Date);
            Assert.Equal(_availableDesks.First().Id, savedDeskBooking.DeskId);
        }
Exemplo n.º 4
0
        public void ShouldSaveDeskBooking()
        {
            DeskBooking savedDeskBooking = null;

            _deskBookingRepository.Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(deskBooking => { savedDeskBooking = deskBooking; });
            _processor.BookDesk(_request);

            _deskBookingRepository.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);

            Assert.NotNull(savedDeskBooking);
            Assert.Equal(_request.FirstName, savedDeskBooking.FirstName);
            Assert.Equal(_request.LastName, savedDeskBooking.LastName);
            Assert.Equal(_request.Email, savedDeskBooking.Email);
            Assert.Equal(_request.Date, savedDeskBooking.Date);
        }
Exemplo n.º 5
0
        public void ShouldSaveDeskBooking()
        {
            DeskBooking deskBooking = null;

            mockDeskBookingRepository.Setup(x => x.Save(It.IsAny <DeskBooking>())).Callback <DeskBooking>(booking =>
            {
                deskBooking = booking;
            });
            processor.BookDesk(request);
            mockDeskBookingRepository.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);
            Assert.NotNull(deskBooking);
            Assert.Equal(deskBooking.FirstName, request.FirstName);
            Assert.Equal(deskBooking.LastName, request.LastName);
            Assert.Equal(deskBooking.Email, request.Email);
            Assert.Equal(deskBooking.Date, request.Date);
            Assert.Equal(availableDesks.First().Id, deskBooking.DeskId);
        }
Exemplo n.º 6
0
    public async Task should_save_desk_bookingAsync()
    {
        DeskBooking savedBooking = null;

        _deskBookingMock.Setup(x => x.Save(It.IsAny <DeskBooking>())).Callback <DeskBooking>(deskBooking =>
        {
            savedBooking = deskBooking;
        });
        await _processor.BookDeskAsync(_request);

        _deskBookingMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);
        Assert.IsNotNull(savedBooking);
        Assert.AreEqual(_request.FirstName, savedBooking.FirstName);
        Assert.AreEqual(_request.LastName, savedBooking.LastName);
        Assert.AreEqual(_request.Email, savedBooking.Email);
        Assert.AreEqual(_request.Phone, savedBooking.Phone);
        Assert.AreEqual(_desks.First().Id, savedBooking.DeskId);
    }
Exemplo n.º 7
0
        public void ShouldSaveBookDesk()
        {
            var availableDesks = new List <Desk>
            {
                new Desk
                {
                    Id = 1,
                },
                new Desk
                {
                    Id = 2,
                },
            };

            var request = new DeskBookingRequest()
            {
                FirstName = "Pratik",
                LastName  = "Nandagawali",
                Email     = "*****@*****.**",
                Date      = new DateTime(2021, 03, 28),
            };

            DeskBooking savedDeskBooking = null;

            this.deskBookingRepositoryMock.Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(
                deskBooking =>
            {
                savedDeskBooking = deskBooking;
            });
            this.deskRepositoryMock.Setup(
                x => x.GetAvailableDesks(request.Date)).Returns(availableDesks);

            this.processor.BookDesk(request);

            this.deskBookingRepositoryMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);
            savedDeskBooking.ShouldNotBeNull();
            savedDeskBooking.FirstName.ShouldBeEquivalentTo(request.FirstName);
            savedDeskBooking.LastName.ShouldBeEquivalentTo(request.LastName);
            savedDeskBooking.Email.ShouldBeEquivalentTo(request.Email);
            savedDeskBooking.Date.ShouldBeEquivalentTo(request.Date);
        }
Exemplo n.º 8
0
        public void ShoudSaveDeskBooking()
        {
            DeskBooking savedDeskBooking = null;

            _deskBookingRepositoryMock.Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(deskBooking =>
            {
                savedDeskBooking = deskBooking;
            });

            _processor.BookDesk(_request); //Now verify the object is saved
            _deskBookingRepositoryMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);
            Assert.NotNull(savedDeskBooking);

            Assert.Equal(_request.Fn, savedDeskBooking.Fn);
            Assert.Equal(_request.Ln, savedDeskBooking.Ln);
            Assert.Equal(_request.Email, savedDeskBooking.Email);
            Assert.Equal(_request.Date, savedDeskBooking.Date);
            Assert.Equal(_availableDesks.First().Id, savedDeskBooking.DeskId);
        }
        public void ShouldSaveDeskBookingRequest()
        {
            DeskBooking deskBookingShouldBeSaved = null;

            _deskBookingRepositoryMock.Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(deskbooking =>
            {
                deskBookingShouldBeSaved = deskbooking;
            });
            _processor.BookDesk(_request);


            _deskBookingRepositoryMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);

            Assert.NotNull(deskBookingShouldBeSaved);
            Assert.Equal(deskBookingShouldBeSaved.FirstName, _request.FirstName);
            Assert.Equal(deskBookingShouldBeSaved.LastName, _request.LastName);
            Assert.Equal(deskBookingShouldBeSaved.Email, _request.Email);
            Assert.Equal(deskBookingShouldBeSaved.Date, _request.Date);
            Assert.Equal(_availableDesks.First().Id, deskBookingShouldBeSaved.DeskId);
        }
        public void ShouldSaveDeskBooking()
        {
            DeskBooking savedDeskBooking = null;

            _deskBookingRepositoryMock
            .Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(deskBooking =>
            {
                savedDeskBooking = deskBooking;
            });

            _processor.BookDesk(_request);

            _deskBookingRepositoryMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);

            Assert.That(savedDeskBooking, Is.Not.Null);
            Assert.That(_request.FirstName, Is.EqualTo(savedDeskBooking.FirstName));
            Assert.That(_request.LastName, Is.EqualTo(savedDeskBooking.LastName));
            Assert.That(_request.Email, Is.EqualTo(savedDeskBooking.Email));
            Assert.That(_request.Date, Is.EqualTo(savedDeskBooking.Date));
            Assert.That(_availableDesks.First().Id, Is.EqualTo(savedDeskBooking.DeskId));
        }
        public void ShouldSaveTheDeskBooking()
        {
            //arrange
            var options = new DbContextOptionsBuilder <DeskBookerContext>()
                          .UseInMemoryDatabase(databaseName: "ShouldSaveTheDeskBooking")
                          .Options;

            var deskBooking = new DeskBooking
            {
                FirstName = "John",
                LastName  = "Doe",
                Date      = new DateTime(2021, 5, 5),
                Email     = "*****@*****.**",
                DeskId    = 1
            };

            //act
            using (var context = new DeskBookerContext(options))
            {
                var repository = new DeskBookingRepository(context);
                repository.Save(deskBooking);
            }

            //assert
            using (var context = new DeskBookerContext(options))
            {
                var bookings          = context.DeskBookings.ToList();
                var storedDeskBooking = bookings.First();

                Assert.That(bookings, Has.Count.EqualTo(1));

                Assert.That(deskBooking.FirstName, Is.EqualTo(storedDeskBooking.FirstName));
                Assert.That(deskBooking.LastName, Is.EqualTo(storedDeskBooking.LastName));
                Assert.That(deskBooking.Email, Is.EqualTo(storedDeskBooking.Email));
                Assert.That(deskBooking.DeskId, Is.EqualTo(storedDeskBooking.DeskId));
                Assert.That(deskBooking.Date, Is.EqualTo(storedDeskBooking.Date));
            }
        }
Exemplo n.º 12
0
        public void ShouldSaveTheDeskBooking()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <DeskBookerContext>()
                          .UseInMemoryDatabase(databaseName: "ShouldSaveTheDeskBooking")
                          .Options;

            var deskBooking = new DeskBooking
            {
                FirstName = "Thomas",
                LastName  = "Huber",
                Date      = new DateTime(2020, 1, 25),
                Email     = "*****@*****.**",
                DeskId    = 1
            };

            // Act
            using (var context = new DeskBookerContext(options))
            {
                var repository = new DeskBookingRepository(context);
                repository.Save(deskBooking);
            }

            // Assert
            using (var context = new DeskBookerContext(options))
            {
                var bookings = context.DeskBooking.ToList();

                Assert.AreEqual(1, bookings.Count);
                var storedDeskBooking = bookings.Single();

                Assert.AreEqual(deskBooking.FirstName, storedDeskBooking.FirstName);
                Assert.AreEqual(deskBooking.LastName, storedDeskBooking.LastName);
                Assert.AreEqual(deskBooking.Email, storedDeskBooking.Email);
                Assert.AreEqual(deskBooking.DeskId, storedDeskBooking.DeskId);
                Assert.AreEqual(deskBooking.Date, storedDeskBooking.Date);
            }
        }
Exemplo n.º 13
0
        public void ShouldSaveDeskBooking()
        {
            DeskBooking savedDeskBooking = null;

            _deskBookingRepositoryMock.Setup(x => x.Save(It.IsAny <DeskBooking>()))
            .Callback <DeskBooking>(deskBooking =>
            {
                savedDeskBooking = deskBooking;
            });     // set up a repo save  for any desk book obj

            //define safeback

            _processor.BookDesk(_request); // verify that desk book object is safe

            _deskBookingRepositoryMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);

            Assert.NotNull(savedDeskBooking);
            Assert.Equal(_request.FirstName, savedDeskBooking.FirstName);
            Assert.Equal(_request.LastName, savedDeskBooking.LastName);
            Assert.Equal(_request.Email, savedDeskBooking.Email);
            Assert.Equal(_request.Date, savedDeskBooking.Date);
            Assert.Equal(_availableDesks.First().Id, savedDeskBooking.DeskId);
        }
Exemplo n.º 14
0
        public void ShouldSaveTheDeskBooking()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <DeskBookerContext>()
                          .UseInMemoryDatabase(databaseName: "ShouldSaveTheDeskBooking")
                          .Options;

            var deskBooking = new DeskBooking
            {
                FirstName = "Fabio",
                LastName  = "Oquendo",
                Date      = new DateTime(2021, 4, 10),
                Email     = "*****@*****.**",
                DeskId    = 1
            };

            // Act
            using (var context = new DeskBookerContext(options))
            {
                var repository = new DeskBookingRepository(context);
                repository.Save(deskBooking);
            }

            // Assert
            using (var context = new DeskBookerContext(options))
            {
                var bookings          = context.DeskBooking.ToList();
                var storedDeskBooking = Assert.Single(bookings);

                Assert.Equal(deskBooking.FirstName, storedDeskBooking.FirstName);
                Assert.Equal(deskBooking.LastName, storedDeskBooking.LastName);
                Assert.Equal(deskBooking.Email, storedDeskBooking.Email);
                Assert.Equal(deskBooking.DeskId, storedDeskBooking.DeskId);
                Assert.Equal(deskBooking.Date, storedDeskBooking.Date);
            }
        }
        public void ShouldSaveDeskBooking()
        {
            DeskBooking savedDeskBooking = null;

            // checks to make sure this is a deskbooking
            _deskBookingRepositoryMock.Setup(x => x.Save(It.IsAny <DeskBooking>()))

            .Callback <DeskBooking>(deskBooking =>
            {
                savedDeskBooking = deskBooking;
            });

            _processor.BookDesk(_request);
            // verifies the saved object is a desk booking
            _deskBookingRepositoryMock.Verify(x => x.Save(It.IsAny <DeskBooking>()), Times.Once);

            Assert.NotNull(savedDeskBooking);

            Assert.Equal(_request.FirstName, savedDeskBooking.FirstName);
            Assert.Equal(_request.LastName, savedDeskBooking.LastName);
            Assert.Equal(_request.Email, savedDeskBooking.Email);
            Assert.Equal(_request.Date, savedDeskBooking.Date);
            Assert.Equal(_availableDesks.First().Id, savedDeskBooking.DeskId);
        }
Exemplo n.º 16
0
 public void Save(DeskBooking desk)
 {
     _context.DeskBooking.Add(desk);
     _context.SaveChanges();
 }
Exemplo n.º 17
0
 public DeskBooking Save(DeskBooking newDeskBooking)
 {
     _deskBookerContext.Add(newDeskBooking);
     _deskBookerContext.SaveChanges();
     return(newDeskBooking);
 }
Exemplo n.º 18
0
 public void Save(DeskBooking deskBooking)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 19
0
 public void Save(DeskBooking deskBooking)
 {
     _unitOfWork.Repository <DeskBooking>().AddAsync(deskBooking);
 }