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 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); }