public void CheckBookingEventExist_ExistedEventInfo_MatchedEvent() { // Setup dependency var settingsMock = new Mock<ISettings>(); var uowMock = new Mock<IUnitOfWork>(); var repositoryMock = new Mock<IRepository>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange Guid sourceUserId = Guid.NewGuid(); Guid targetUserId = Guid.NewGuid(); UserDto sourceUser = new UserDto { Id = sourceUserId }; UserDto targetUser = new UserDto { Id = targetUserId }; string shortDescription = "Test description"; BookingEvent bookingEvent = new BookingEvent { Id = Guid.NewGuid(), SourceUser = new User { Id = sourceUserId }, TargetUser = new User { Id = targetUserId }, ShortDescription = shortDescription }; BookingEvent[] bookingEvents = new BookingEvent[] { bookingEvent }; repositoryMock.Setup(r => r.Query<BookingEvent>()).Returns(bookingEvents.AsQueryable()); BookingEventDto actualBookingEventDto; // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); actualBookingEventDto = bookingService.CheckBookingEventExist( sourceUser, targetUser, shortDescription); // Assert Assert.AreEqual(bookingEvent.Id, actualBookingEventDto.Id); }
public void RatingCalculator_GuidId() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(r => r.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange data Guid id = Guid.NewGuid(); User user = new User { Id = id }; Booking booking = new Booking { Id = Guid.NewGuid(), Specialist = user }; Call call1 = new Call { Id = Guid.NewGuid(), Booking = booking, Rating = 2 }; Call call2 = new Call { Id = Guid.NewGuid(), Booking = booking, Rating = 4 }; User[] users = new User[] { user }; repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable()); Booking[] bookings = new Booking[] { booking }; repositoryMock.Setup(r => r.Query<Booking>()).Returns(bookings.AsQueryable()); Call[] calls = new Call[] { call1, call2 }; repositoryMock.Setup(r => r.Query<Call>()).Returns(calls.AsQueryable()); double expectedValue = 3; // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); double currentValue = bookingService.RatingCalculator(id); // Assert repositoryMock.Verify(r => r.Query<Call>());//.Where(c=>c.Booking.Specialist.Id == id)); Assert.AreEqual(expectedValue, currentValue); }
public void GetListBookingByStatus_UsingKeyword_SpecialistRole_ConfirmStatus() { // Setup dependence var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange Role role = Role.Specialist; BookingStatus status = BookingStatus.Confirmed; string keyword = "Master"; // Arrange user Guid specialistId = Guid.NewGuid(); User specialist = new User { Id = specialistId }; // Arrange specialList User customer = new User { Id = Guid.NewGuid(), FirstName = keyword }; List<User> users = new List<User>(); users.Add(customer); users.Add(specialist); repositoryMock.Setup(r => r.Query<User>()) .Returns(users.AsQueryable()); Guid bookingId = Guid.NewGuid(); Booking booking = new Booking { Id = bookingId, Customer = customer, Specialist = specialist, EndTime = DateTime.Now.AddDays(1), Status = status }; List<Booking> bookings = new List<Booking>(); bookings.Add(booking); repositoryMock.Setup(r => r.Query<Booking>()) .Returns(bookings.AsQueryable()); // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); var listBooking = bookingService.GetListBookingByStatus( specialistId, role, status, keyword); // Assert Assert.AreEqual(bookings.Count(), listBooking.Count()); }
public void CreateBookingEvent_BookingEventDto_BookingEventDto() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>()) .Returns(uowMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object); UserDto user = new UserDto() { Email = "*****@*****.**" }; // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.CreateBookingEvent(new BookingEventDto() { TargetUser = user }); // Assert repositoryMock.Verify(repo => repo .Insert<BookingEvent>(It.IsAny<BookingEvent>())); uowMock.Verify(repo => repo.Save()); }
public void GetListBookingByStatus_SpecialistRole_BookingTypeStandard() { // Setup dependence var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange Role role = Role.Specialist; BookingStatus status = BookingStatus.Requested; BookingType bookingType = BookingType.StandardHour; // Arrange user Guid customerId = Guid.NewGuid(); User customer = new User { Id = customerId }; List<User> users = new List<User>(); users.Add(customer); repositoryMock.Setup(r => r.Query<User>()) .Returns(users.AsQueryable()); // Arrange booking Guid bookingId = Guid.NewGuid(); Booking booking = new Booking { Id = bookingId, Specialist = customer, Type = bookingType, Status = status }; List<Booking> bookings = new List<Booking>(); bookings.Add(booking); repositoryMock.Setup(r => r.Query<Booking>()) .Returns(bookings.AsQueryable()); // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); var listBooking = bookingService.GetListBookingByStatus( customerId, role, status); // Assert Assert.AreEqual(bookings.Count(), listBooking.Count()); }
public void GetById_AnyId_CallsFindByIdMethodOfRepository() { // Setup dependency var settingsMock = new Mock<ISettings>(); var uowMock = new Mock<IUnitOfWork>(); var repositoryMock = new Mock<IRepository>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange Guid id = Guid.NewGuid(); // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.GetById(id); // Assert repositoryMock.Verify(repo => repo.FindById<Booking>(id)); }
public void GetByBookingAndShortDescription_UsingBookingIdAndShortDescription() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(r => r.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange data string description = "Test description"; Guid id = Guid.NewGuid(); BookingDto bookingDto = new BookingDto { Id = id }; Booking booking = new Booking { Id = id }; BookingEvent bookingEvent = new BookingEvent { Id = id, Booking = booking, ShortDescription = description }; List<BookingDto> listBookingDto = new List<BookingDto>(); listBookingDto.Add(bookingDto); List<string> descriptions = new List<string>(); descriptions.Add(description); BookingEvent[] bookingEvents = new BookingEvent[] { bookingEvent }; repositoryMock.Setup(r => r.Query<BookingEvent>()).Returns(bookingEvents.AsQueryable()); List<BookingEventDto> bookingEventDtos = new List<BookingEventDto>(); // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingEventDtos = bookingService .GetByBookingAndShortDescription(listBookingDto, descriptions); // Assert repositoryMock.Verify(r => r.Query<BookingEvent>()); Assert.AreEqual(id, bookingEventDtos[0].Id); }
public void GetBookingEventListByTargetUserId_GuidId_ListOfBookingEventDto() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(r => r.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.GetBookingEventListByTargetUserId(Guid.NewGuid()); // Assert repositoryMock.Verify(repo => repo.Query<BookingEvent>()); }
public void GetBookingReferenceNo_GetNextReferenceNo_From9999999999() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(r => r.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange data Booking booking = new Booking { Id = Guid.NewGuid(), ReferenceNo = "999999999-9" }; Booking[] bookingEvents = new Booking[] { booking }; repositoryMock.Setup(r => r.Query<Booking>()).Returns(bookingEvents.AsQueryable()); string expectedValue = "000000000-0"; // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); string currentValue = bookingService.GetBookingReferenceNo(); // Assert repositoryMock.Verify(r => r.Query<Booking>()); Assert.AreEqual(expectedValue, currentValue); }
public void Update_BookingDto_BookingDto() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>()) .Returns(uowMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object); Guid id = Guid.NewGuid(); BookingDto bookingDto = new BookingDto { Id = id }; // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.Update(bookingDto); // Assert repositoryMock.Verify(repo => repo .Update<Booking>(It.Is<Booking>(b => b.Id == bookingDto.Id))); uowMock.Verify(uow => uow.Save()); }
public void UpdateBookingStatus_NewGuid_Confirmed_Success() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>()) .Returns(uowMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object); Guid id = Guid.NewGuid(); Booking booking = new Booking { Id = id }; repositoryMock.Setup(r => r.FindById<Booking>(id)).Returns(booking); // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.UpdateBookingStatus(id, BookingStatus.Confirmed); // Assert repositoryMock.Verify(repo => repo.Update<Booking>( It.Is<Booking>(b => b.Id == id && b.Status == BookingStatus.Confirmed))); uowMock.Verify(uow => uow.Save()); }
public void UpdateBookingForDeferOrReSchedule_NewGuid_5_True() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>()) .Returns(uowMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object); Guid id = Guid.NewGuid(); Booking booking = new Booking { Id = id }; repositoryMock.Setup(r => r.FindById<Booking>(id)).Returns(booking); // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.UpdateBookingForDeferOrReSchedule(id, 5); // Assert repositoryMock.Verify(repo => repo.FindById<Booking>(id)); repositoryMock.Verify(repo => repo.Update<Booking>( It.Is<Booking>(b => b.Id == id && b.Deferral == 5 && b.StartTime == b.EndTime && b.Status == BookingStatus.SpecialistRescheduled))); uowMock.Verify(uow => uow.Save()); }
public void UpdateBookingEvent_BookingEventDto_BookingEventDto() { var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(x => x.GetInstance<IRepository>()) .Returns(repositoryMock.Object); serviceLocatorMock.Setup(x => x.GetInstance<IUnitOfWork>()) .Returns(uowMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object); var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); bookingService.UpdateBookingEvent(new BookingEventDto()); repositoryMock.Verify(repo => repo.Update<BookingEvent>(It.IsAny<BookingEvent>())); uowMock.Verify(uow => uow.Save()); }
public void RatingCalculator_NullCall() { // Setup Dependence var settingsMock = new Mock<ISettings>(); var repositoryMock = new Mock<IRepository>(); var uowMock = new Mock<IUnitOfWork>(); var serviceLocatorMock = new Mock<IServiceLocator>(); serviceLocatorMock.Setup(r => r.GetInstance<IRepository>()) .Returns(repositoryMock.Object); ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object); // Arrange data Guid id = Guid.NewGuid(); User user = new User { Id = id }; repositoryMock.Setup(r => r.Query<Booking>()).Returns(new List<Booking>().AsQueryable()); double expectedValue = 0; // Act var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object); double currentValue = bookingService.RatingCalculator(id); // Assert repositoryMock.Verify(r => r.Query<Call>()); Assert.AreEqual(expectedValue, currentValue); }