public async Task GetAsync_OwnerNotFound_ThrowsException()
        {
            TestingObject <ReportService> testingObject = this.GetTestingObject();

            Guid reportIdArg = Guid.NewGuid();

            var mockDbContext = testingObject.GetDependency <Mock <IDatabaseContext> >();

            var report = new ReportMetadataSql
            {
                Created = DateTime.UtcNow.AddYears(-2),
                OwnerId = Guid.NewGuid()
            };

            mockDbContext
            .Setup(m => m.FindSingleAsync <ReportMetadataSql>(It.Is <Guid>(id => id == reportIdArg)))
            .ReturnsAsync(report);

            mockDbContext
            .Setup(m => m.FindSingleAsync <UserSql>(It.Is <Guid>(id => id == report.OwnerId)))
            .ReturnsAsync((UserSql)null);

            ReportService reportService = testingObject.GetResolvedTestingObject();
            await Assert.ThrowsAsync <Exception>(async()
                                                 => await reportService.GetAsync(reportIdArg));
        }
Ejemplo n.º 2
0
        private async Task FillDataBase(TestingObject <OperationRepository> testingObject)
        {
            var context = testingObject.GetDependency <ApplicationDbContext>();

            await context.Operations.AddRangeAsync(CreateOperationEntity(TestId1), CreateOperationEntity(TestId2),
                                                   CreateOperationEntity(TestId3), CreateOperationEntity(TestId4, true));
        }
        public void Find_InvalidQuery_ThrowArgumentException()
        {
            TestingObject <ProductRepository> testingObject = this.GetTestingObject();
            var mockProductCommand = testingObject.GetDependency <Mock <IProductCommand <Product, bool> > >();

            Func <Product, bool> query = null;

            mockProductCommand
            .Setup(c => c.Command())
            .Returns(query);

            ProductRepository prodRepository = testingObject.GetResolvedTestingObject();
            var a = testingObject.GetDependency <Mock <IProductCommand <Product, bool> > >();

            Assert.Throws <ArgumentException>(() => prodRepository.Find(It.IsAny <IProductCommand <Product, bool> >()));
        }
Ejemplo n.º 4
0
        private async Task FillDataBase(TestingObject <FileDatabase> testObject)
        {
            var context = testObject.GetDependency <FilesDbContext>();

            _big   = Properties.Resources.bm19_07777_Covers_FB_001_Einzelform_Umschlagen_LACK_pdf;
            _small = Properties.Resources.bm19_07777_Covers_FB_001_Einzelform_Umschlagen_LACK_tif;

            _bigSize   = _big.Length;
            _smallSize = _small.Length;

            _databaseSize = _bigSize + _smallSize;

            var oldEi = new FileBlobInfoEntity {
                CreationTime = new DateTime(2015, 1, 1), FileName = "Old", Size = _bigSize
            };
            var newEi = new FileBlobInfoEntity {
                CreationTime = new DateTime(2017, 1, 1), FileName = "New", Size = _smallSize
            };

            var oldE = new FileBlobEntity {
                Data = _big, Key = OldConst
            };
            var newE = new FileBlobEntity {
                Data = _small, Key = NewConst
            };

            await context.FileInfos.AddRangeAsync(oldEi, newEi);

            await context.Blobs.AddRangeAsync(oldE, newE);
        }
Ejemplo n.º 5
0
        private async Task FillDatabase(TestingObject <FileRepository> repo)
        {
            var context = repo.GetDependency <ApplicationDbContext>();

            await context.Files.AddRangeAsync(
                new FileEntity { Age = DateTime.Now, Id = 1, IsDeleted = false, IsRequested = true, Name = Unrequestet, Path = Unrequestet, User = "******" },
                new FileEntity { Age = DateTime.Now, Id = 2, IsDeleted = false, IsRequested = true, Name = Requested, Path = Requested, User = "******" });
        }
        public void Get_ValidArgument_ReturnResults(string usage, string startBy, int expected)
        {
            TestingObject <ProductRepository> testingObject = this.GetTestingObject();
            var mockDataContext = testingObject.GetDependency <Mock <IDataContext <Product> > >();

            mockDataContext.Setup(d => d.Data).Returns(products);
            ProductService        prodService = new ProductService(testingObject.GetResolvedTestingObject());
            IEnumerable <Product> actual      = prodService.Get(usage, startBy);

            Assert.AreEqual(expected, actual.Count <Product>());
        }
        public void Find_validQuery_ReturnsCorrectProducts()
        {
            TestingObject <ProductRepository> testingObject = this.GetTestingObject();

            var mockDataContext = testingObject.GetDependency <Mock <IDataContext <Product> > >();

            IList <Product> products = new List <Product> {
                new Product {
                    Artist = "Tinie Tempah", Title = "Frisky (Live from SoHo)", Usages = "digital download", StartDate = DateTime.Parse("2012/02/01")
                },
                new Product {
                    Artist = "Tinie Tempah", Title = "Frisky (Live from SoHo)", Usages = "streaming", StartDate = DateTime.Parse("2012/02/01")
                },
                new Product {
                    Artist = "Tinie Tempah", Title = "Miami 2 Ibiza", Usages = "digital download", StartDate = DateTime.Parse("2012/02/01")
                },
                new Product {
                    Artist = "Tinie Tempah", Title = "Till I'm Gone", Usages = "digital download", StartDate = DateTime.Parse("2012/08/01")
                }
            };

            mockDataContext
            .Setup(d => d.Data)
            .Returns(products);

            Func <Product, bool> query = (product => product.Usages == "digital download");

            var mockProductCommand = testingObject.GetDependency <Mock <IProductCommand <Product, bool> > >();

            mockProductCommand
            .Setup(c => c.Command())
            .Returns(query);

            ProductRepository prodRepository = testingObject.GetResolvedTestingObject();
            var a = testingObject.GetDependency <Mock <IProductCommand <Product, bool> > >();

            Assert.AreEqual(3, prodRepository.Find(mockProductCommand.Object).Count <Product>());
        }
        public async Task GetAsync_ReportNotFound_ThrowsException()
        {
            TestingObject <ReportService> testingObject = this.GetTestingObject();

            Guid reportIdArg   = Guid.NewGuid();
            var  mockDbContext = testingObject.GetDependency <Mock <IDatabaseContext> >();

            mockDbContext
            .Setup(m => m.FindSingleAsync <ReportMetadataSql>(It.Is <Guid>(id => id == reportIdArg)))
            .ReturnsAsync((ReportMetadataSql)null);

            ReportService reportService = testingObject.GetResolvedTestingObject();
            await Assert.ThrowsAsync <Exception>(async()
                                                 => await reportService.GetAsync(reportIdArg));
        }
Ejemplo n.º 9
0
        public async Task GetAsync_UserNotFound_ThrowsException()
        {
            TestingObject <UserService> testingObject = this.GetTestingObject();

            Guid userIdArg = Guid.NewGuid();

            var mockDbContext = testingObject.GetDependency <Mock <IDatabaseContext> >();

            mockDbContext
            .Setup(dbc => dbc.FindSingleAsync <UserSql>(It.Is <Guid>(id => id == userIdArg)))
            .ReturnsAsync((UserSql)null);

            UserService userService = testingObject.GetResolvedTestingObject();
            await Assert.ThrowsAsync <Exception>(async()
                                                 => await userService.GetAsync(userIdArg));
        }
Ejemplo n.º 10
0
        public async Task GetAsync_Success_Updated_ReturnsCorrectResult()
        {
            TestingObject <ReportService> testingObject = this.GetTestingObject();

            Guid reportIdArg = Guid.NewGuid();

            var mockDbContext = testingObject.GetDependency <Mock <IDatabaseContext> >();

            var report = new ReportMetadataSql
            {
                Created     = DateTime.UtcNow.AddYears(-2),
                OwnerId     = Guid.NewGuid(),
                LastUpdated = DateTime.UtcNow,
                Title       = "Report Title"
            };

            mockDbContext
            .Setup(m => m.FindSingleAsync <ReportMetadataSql>(It.Is <Guid>(id => id == reportIdArg)))
            .ReturnsAsync(report);

            var owner = new UserSql
            {
                Enabled   = true,
                FirstName = "Mary",
                LastName  = "Jane"
            };

            mockDbContext
            .Setup(m => m.FindSingleAsync <UserSql>(It.Is <Guid>(id => id == report.OwnerId)))
            .ReturnsAsync(owner);

            ReportService reportService = testingObject.GetResolvedTestingObject();

            ReportMetadata result = await reportService.GetAsync(reportIdArg);

            Assert.EndsWith("(Revision)", result.Title);
        }
Ejemplo n.º 11
0
        public async Task GetAsync_Success_ReturnsCorrectResult()
        {
            TestingObject <UserService> testingObject = this.GetTestingObject();

            Guid userIdArg = Guid.NewGuid();

            var mockDbContext = testingObject.GetDependency <Mock <IDatabaseContext> >();

            var userSql = new UserSql
            {
                FirstName = "Mary",
                LastName  = "Jane"
            };

            mockDbContext
            .Setup(dbc => dbc.FindSingleAsync <UserSql>(It.Is <Guid>(id => id == userIdArg)))
            .ReturnsAsync(userSql);

            UserService userService = testingObject.GetResolvedTestingObject();
            User        result      = await userService.GetAsync(userIdArg);

            Assert.Equal(userSql.FirstName, result.FirstName);
            Assert.Equal(userSql.LastName, result.LastName);
        }