private static T Create <T>(DeskBookingRequest request) where T : DeskBookingBase, new()
 {
     return(new T
     {
         FirstName = request.FirstName,
         LastName = request.LastName,
         Email = request.Email,
         Date = request.Date,
     });
 }
        public DeskBookingResult BookDesk(DeskBookingRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            _deskBookingRepository.Save(Create <DeskBooking>(request));

            return(Create <DeskBookingResult>(request));
        }
        public void ShouldThrowExceptionIfRequestIsNull()
        {
            // Arrange
            DeskBookingRequest request = null;

            // Act
            Action action = () => _processor.BookDesk(request);

            // Assert
            var exception = Assert.Throws <ArgumentNullException>(action);

            Assert.Equal("request", exception.ParamName);
        }
 public DeskBookingResult BookDesk(DeskBookingRequest request)
 {
     if (request == null)
     {
         throw new ArgumentNullException(nameof(request));
     }
     return(new DeskBookingResult()
     {
         FirstName = request.FirstName,
         LastName = request.LastName,
         Email = request.Email,
         Date = request.Date
     });
 }
Exemplo n.º 5
0
        public DeskBookingRequestProcessorTests()
        {
            // Arrange
            _request = new DeskBookingRequest()
            {
                FirstName = "Alex",
                LastName  = "Torres",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 01, 28)
            };

            _deskBookingRepoMock = new Mock <IDeskBookingRepository>();

            _processor = new DeskBookingRequestProcessor(_deskBookingRepoMock.Object);
        }
        public DeskBookingResult BookDesk(DeskBookingRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var availableDesk = _deskRespository.GetAvailableDesks(request.Date);

            if (availableDesk.FirstOrDefault() is Desk availableDesks)
            {
                var deskBooking = Create <DeskBooking>(request);
                deskBooking.DeskId = availableDesks.Id;
                _deskBookingRespository.Save(deskBooking);
            }
            return(Create <DeskBookingResult>(request));
        }
Exemplo n.º 7
0
        public void ShouldReturnTheDeskBookingResultWithRequestedValues()
        {
            var request = new DeskBookingRequest()
            {
                FirstName = "Pratik",
                LastName  = "Nandagawali",
                Email     = "*****@*****.**",
                Date      = new DateTime(2021, 03, 28),
            };

            var result = this.processor.BookDesk(request);

            result.ShouldNotBeNull();
            result.FirstName.ShouldBeEquivalentTo(request.FirstName);
            result.LastName.ShouldBeEquivalentTo(request.LastName);
            result.Email.ShouldBeEquivalentTo(request.Email);
            result.Date.ShouldBeEquivalentTo(request.Date);
        }
        public DeskBookingResult BookDesk(DeskBookingRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            var deskBookingResult = this.Create <DeskBookingResult>(request);
            var availableDesks    = this.deskRepository.GetAvailableDesks(request.Date);

            if (availableDesks.Any())
            {
                deskBookingResult.ResultCode = DeskBookingResultCode.Success;
                this.deskBookingRepository.Save(this.Create <DeskBooking>(request));
            }

            return(deskBookingResult);
        }
Exemplo n.º 9
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);
        }
 public DeskBookingRequestProcessorTest()
 {
     _request = new DeskBookingRequest
     {
         FirstName = "David",
         LastName  = "Smith",
         Email     = "*****@*****.**",
         Date      = new DateTime(2020, 03, 13)
     };
     _availableDesks = new List <Desk> {
         new Desk {
             Id = 1
         }
     };
     // _availableDesks = new List<Desk> { new Desk() };
     _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
     _deskRepositoryMock        = new Mock <IDeskRepository>();
     _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date)).Returns(_availableDesks);
     _processor = new DeskBookingRequestProcessor(_deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
 }
        public DeskBookingRequestProcessorTests()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Chandu",
                LastName  = "Siddi",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 1, 28)
            };
            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };
            _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
            _deskBookingMock           = new Mock <IDeskRepository>();
            _deskBookingMock.Setup(x => x.GetAvailableDesks(_request.Date)).Returns(_availableDesks);

            _processor = new DeskBookngRequestProcessor(_deskBookingRepositoryMock.Object, _deskBookingMock.Object);
        }
 public DeskBookingRequestProcessorTests()
 {
     _request = new DeskBookingRequest
     {
         FirstName = "Wojtek",
         LastName  = "P",
         Email     = "*****@*****.**",
         Date      = new DateTime(2020, 1, 28)
     };
     _availableDesks = new List <Desk>()
     {
         new Desk {
             Id = 7
         }
     };
     _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
     _deskRepositoryMock        = new Mock <IDeskRepository>();
     _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date)).Returns(_availableDesks);
     _processor = new DeskBookingRequestProcessor(_deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
 }
        public DeskBookingRequestProcessorTests()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Thomas",
                LastName  = "Huber",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 1, 28)
            };

            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };
            _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
            _deskRepositoryMock        = new Mock <IDeskRepository>();
            _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date)).Returns(_availableDesks);
            _processor = new DeskBookingRequestProcessor(_deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
        }
Exemplo n.º 14
0
    public void Initialize()
    {
        _request = new DeskBookingRequest
        {
            FirstName = "First Name",
            LastName  = "Last Name",
            Email     = "Email",
            Phone     = "Phone"
        };
        _desks = new List <Desk> {
            new Desk {
                Id = 1, BookingDate = new DateTime()
            }
        };
        _deskBookingMock    = new Mock <IDeskBookingRepository>();
        _deskRepositoryMock = new Mock <IDeskRepository>();
        _deskRepositoryMock.Setup(x => x.GetAvailableDesks(It.IsAny <DateTime>()))
        .ReturnsAsync(_desks);

        _processor = new DeskBookingRequestProcessor(_deskBookingMock.Object, _deskRepositoryMock.Object);
    }
        public void ShouldReturnDeskBookingResultWithRequestValues()
        {
            //arrange
            var request = new DeskBookingRequest
            {
                FirstName = "Jon",
                LastName  = "Smart",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 10, 1)
            };

            //act
            DeskBookingResult result = _processor.BookDesk(request);

            //assert
            Assert.NotNull(result);
            Assert.Equal(request.FirstName, result.FirstName);
            Assert.Equal(request.LastName, result.LastName);
            Assert.Equal(request.Email, result.Email);
            Assert.Equal(request.Date, result.Date);
        }
        public void ShouldReturnDeskBookingResultWithValueRequest()
        {
            var request = new DeskBookingRequest
            {
                FirstName = "Joms",
                LastName  = "Huber",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 2, 27)
            };


            //Act
            DeskBookingResult result = _processor.BookDesk(request);

            //assert
            Assert.NotNull(result);
            Assert.Equal(request.FirstName, result.FirstName);
            Assert.Equal(request.LastName, result.LastName);
            Assert.Equal(request.Email, result.Email);
            Assert.Equal(request.Date, result.Date);
        }
        public void ShouldReturnDeskBookingResultWithRequestValues()
        {
            // Arrange
            var request = new DeskBookingRequest
            {
                FirstName = "Thomas",
                LastName  = "Huber",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 1, 28)
            };

            // Act
            DeskBookingResult result = _processor.BookDesk(request);

            // Assert
            Assert.NotNull(result);
            Assert.Equal(request.FirstName, result.FirstName);
            Assert.Equal(request.LastName, result.LastName);
            Assert.Equal(request.Email, result.Email);
            Assert.Equal(request.Date, result.Date);
        }
Exemplo n.º 18
0
        public DeskBookingResult BookDesk(DeskBookingRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            // Static Create<T> method, create return result.
            var result = Create <DeskBookingResult>(request);

            // Determine if booking is available, search by date.
            var availableDesks = _deskRepository.GetAvailableDesks(request.Date);

            // Check for return booking.
            if (availableDesks.FirstOrDefault() is Desk availableDesk)
            {
                // Booking is available, create request.
                var deskBooking = Create <DeskBooking>(request);

                // Assign booking Id.
                deskBooking.DeskId = availableDesk.Id;

                // Save booking.
                _deskBookingRepository.Save(deskBooking);

                // Assign booking Id to result.
                result.DeskBookingId = deskBooking.Id;

                // Return status code and result.
                result.Code = DeskBookingResultCode.Success;
            }
            else
            {
                // Booking not available, return status code.
                result.Code = DeskBookingResultCode.NoDeskAvailable;
            }

            // Return booking result :: status codes "Success" or "NoDeskAvailable".
            return(result);
        }
Exemplo n.º 19
0
        public DeskBookingRequestProcessorTests()
        {
            _request = new DeskBookingRequest()
            {
                FirstName = "Pinky",
                LastName  = "Baring",
                Email     = "*****@*****.**",
                Date      = DateTime.Now
            };
            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };
            //mock
            //dependencies
            _deskBookingRepository = new Mock <IDeskBookingRepository>();
            _deskRepository        = new Mock <IDeskRepository>();
            _deskRepository.Setup(x => x.GetAvailableDesks(_request.Date)).Returns(_availableDesks);

            _processor = new DeskBookingRequestProcessor(_deskBookingRepository.Object, _deskRepository.Object);
        }
Exemplo n.º 20
0
        public DeskBookingResult BookDesk(DeskBookingRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(DeskBookingRequest));
            }
            var result = Create <DeskBookingResult>(request);

            if (_deskRepository.GetAvailableDesks(request.Date).FirstOrDefault() is Desk available)
            {
                var deskbooking = Create <DeskBooking>(request);
                deskbooking.DeskId = available.Id;
                _deskBookingRepository.Save(deskbooking);
                result.BookingDeskId = deskbooking.Id;
                result.Code          = DeskBookingResultCode.Success;
            }
            else
            {
                result.Code = DeskBookingResultCode.NoDeskAvailabel;
            }
            return(result);
        }
 public DeskBookingRequestProcessorTests()
 {
     _request = new DeskBookingRequest
     {
         FirstName = "islam",
         LastName  = "draz",
         Email     = "*****@*****.**",
         Date      = new DateTime(2020, 1, 30)
     };
     _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
     _deskRepositoryMock        = new Mock <IDeskRepository>();
     _availableDesks            = new List <Desk>
     {
         new Desk {
             Id = 10
         }
     };
     _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date)).Returns(
         _availableDesks
         );
     _processor = new DeskBookingRequestProcessor(_deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
 }
        public DeskBookingRequestProcessorTests()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Diego",
                LastName  = "Martins",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 1, 28)
            };

            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };
            _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
            _deskRepositoryMock        = new Mock <IDeskRepository>();
            _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date))
            .Returns(_availableDesks);

            _processor = new DeskBookingRequestProcessor(_deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
        }
        public DeskBookingRequestProcessorTests()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Karthik",
                LastName  = "Srivatsa",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 10, 17)
            };
            _availabeDesks = new List <Desk> {
                new Desk {
                    Id = 18
                }
            };

            _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
            _deskRepositoryMock        = new Mock <IDeskRepository>();

            _deskRepositoryMock.Setup(x => x.GetAvailableDesk(_request.Date)).Returns(_availabeDesks);

            _processor = new DeskBookingRequestProcessor(_deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
        }
        public DeskBookingResult BookDesk(DeskBookingRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(paramName: "request");
            }
            var result         = Create <DeskBookingResult>(request);
            var availableDesks = _deskRepository.GetAvailableDesk(request.Date);

            if (availableDesks.FirstOrDefault() is Desk availableDesk)
            {
                var deskBookingObject = Create <DeskBooking>(request);
                deskBookingObject.DeskId = availableDesk.Id;
                _deskBookingRepository.Save(deskBookingObject);
                result.Code = DeskbookingResultCode.Success;
            }
            else
            {
                result.Code = DeskbookingResultCode.NotAvailable;
            }

            return(result);
        }
Exemplo n.º 25
0
        public void Setup()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Shankhanil",
                LastName  = "Kar",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 6, 10)
            };

            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };

            _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
            _deskRepositoryMock        = new Mock <IDeskRepository>();
            _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date))
            .Returns(_availableDesks);

            _processor = new DeskBookingRequestProcessor(_deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
        }
        public DeskBookingRequestProcessorTests()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Jakub",
                LastName  = "Przybyłowski",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 1, 28)
            };

            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };

            _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
            _deskRepositoryMock        = new Mock <IDeskRepository>();
            _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date))
            .Returns(_availableDesks);

            _processor = new DeskBookingRequestProcessor(
                _deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
        }
Exemplo n.º 27
0
        public DeskBookingRequestProcessorTests()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Fabio",
                LastName  = "Oquendo",
                Email     = "*****@*****.**",
                Date      = new DateTime(2021, 4, 10)
            };

            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };

            _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
            _deskRepositoryMock        = new Mock <IDeskRepository>();
            _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date))
            .Returns(_availableDesks);

            _processor = new DeskBookingRequestProcessor(
                _deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
        }
Exemplo n.º 28
0
        public async Task <DeskBookingResponse> BookDeskAsync(DeskBookingRequest request)
        {
            if (request is null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var desks = await _deskRepository.GetAvailableDesks(request.Date);

            DeskBookingResponse response = Create <DeskBookingResponse>(request);

            if (desks.FirstOrDefault() is Desk availableDesks)
            {
                var deskBooking = Create <DeskBooking>(request);
                deskBooking.DeskId = availableDesks.Id;
                _deskBookingRepository.Save(deskBooking);
                response.ResultCode    = DeskBookingResultCode.Available;
                response.DeskBookingId = deskBooking.Id;
            }
            else
            {
                response.ResultCode = DeskBookingResultCode.NotAvailable;
            }
            return(response);
        }
Exemplo n.º 29
0
        public DeskBookingRequestProcessorTests()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Sam",
                LastName  = "Ige",
                Email     = "*****@*****.**",
                Date      = new DateTime(2020, 1, 28)
            };

            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };

            _deskBookingRepositoryMock = new Mock <IDeskBookingRepository>();
            _deskRepositoryMock        = new Mock <IDeskRepository>();
            _deskRepositoryMock.Setup(x => x.GetAvailableDesks(_request.Date))
            .Returns(_availableDesks);

            _processor = new DeskBookingRequestProcessor(
                _deskBookingRepositoryMock.Object, _deskRepositoryMock.Object);
        }
Exemplo n.º 30
0
        public DeskBookingRequestProcessotTests()
        {
            _request = new DeskBookingRequest
            {
                FirstName = "Sezar",
                LastName  = "Rasoul",
                Email     = "*****@*****.**",
                Date      = new DateTime(2021, 05, 17)
            };

            _availableDesks = new List <Desk> {
                new Desk {
                    Id = 7
                }
            };

            _deskBookingRespository = new Mock <IDeskBookingRespository>();
            _deskRespository        = new Mock <IDeskRespository>();
            _deskRespository.Setup(x => x.GetAvailableDesks(_request.Date))
            .Returns(_availableDesks);

            _processor = new DeskBookingRequestProcessor(
                _deskBookingRespository.Object, _deskRespository.Object);
        }