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