Esempio n. 1
0
        protected virtual void Setup()
        {
            MockRepo.Setup(mr => mr.GetByIdAsync(It.IsAny <long>()))
            .ReturnsAsync((long id) => QueryableCollection.FirstOrDefault(x => x.Id == id));

            MockRepo.Setup(mr => mr.Delete(It.IsAny <TEntity>()))
            .Callback <TEntity>(x => QueryableCollection = QueryableCollection.Where(e => e.Id != x.Id));

            MockRepo.Setup(mr => mr.DeleteAsync(It.IsAny <long>()))
            .Callback <long>(id => QueryableCollection = QueryableCollection.Where(e => e.Id != id))
            .ReturnsAsync(true);

            MockRepo.Setup(mr => mr.GetAll(null)).Returns(QueryableCollection);

            MockRepo.Setup(mr => mr.Add(It.IsAny <TEntity>()))
            .Callback <TEntity>(x => QueryableCollection = QueryableCollection.AsEnumerable().Concat(new[] { x }).AsQueryable());

            MockRepo.Setup(mr => mr.AnyAsync(It.IsAny <Expression <Func <TEntity, bool> > >()))
            .ReturnsAsync((Expression <Func <TEntity, bool> > expr) => QueryableCollection.Any(expr.Compile()));

            MockRepo.Setup(mr => mr.CountAsync(It.IsAny <Expression <Func <TEntity, bool> > >()))
            .ReturnsAsync((Expression <Func <TEntity, bool> > expr) => QueryableCollection.Count(expr.Compile()));

            MockRepo.Setup(mr => mr.CountAsync())
            .ReturnsAsync(() => QueryableCollection.Count());

            Items = MockRepo.Object;
        }
Esempio n. 2
0
        public void Parcel_service_calls_repository_and_returns_grouped_parcels()
        {
            //Arrange
            MockRepo.Setup(p => p.Get <Container>()).Returns(FakeParcels);
            var parcelService = new ParcelService(FakeHandlers, MockRepo.Object, new StandardCriteria());

            //Act
            var result = parcelService.GetGroupedMail();

            //Assert
            var regularDeptGroup = result.ToList().FirstOrDefault(x => x.Handler.Contains("Regular"));

            Assert.IsNotNull(regularDeptGroup);
            Assert.AreEqual(1, regularDeptGroup.Parcels.ToList().Count()); //we expect a parcel record allocated to Regular department
        }
Esempio n. 3
0
        public void GetMonthlySummaries_Should_Return_ResultOfCallingAppropriateServices()
        {
            // arrange
            MockFilePathProvider.Setup(x => x.GetPath()).Returns("path");
            var meterReadings = new List <MeterReading>();

            MockRepo.Setup(x => x.GetMeterReadings("path")).Returns(meterReadings);
            var monthlyData = new List <MonthlySummary>();

            MockAggregateService.Setup(x => x.GetMonthlyData(meterReadings)).Returns(monthlyData);

            // act
            var result = SystemUnderTest.GetMonthlySummaries();

            // assert
            Assert.Equal(monthlyData, result.Value);
            Assert.Equal(ResultCode.Ok, result.ResultCode);
        }
Esempio n. 4
0
        public void GetUsageForDates_Should_Return_ResultOfCallingAppropriateServices()
        {
            // arrange
            MockFilePathProvider.Setup(x => x.GetPath()).Returns("path");
            var meterReadings = new List <MeterReading>();

            MockRepo.Setup(x => x.GetMeterReadings("path")).Returns(meterReadings);
            var usage     = 2;
            var startDate = new DateTime();
            var endDate   = new DateTime();

            MockAggregateService.Setup(x => x.GetUsageBetweenDates(meterReadings, startDate, endDate)).Returns(usage);

            // act
            var result = SystemUnderTest.GetUsageForDates(startDate, endDate);

            // assert
            Assert.Equal(usage, result.Value);
            Assert.Equal(ResultCode.Ok, result.ResultCode);
        }