public void Find_InvalidArgument_ThrowArgumentException()
        {
            TestingObject <ProductRepository> testingObject = this.GetTestingObject();
            ProductRepository prodRepository = testingObject.GetResolvedTestingObject();

            Assert.Throws <ArgumentException>(() => prodRepository.Find(null));
        }
Пример #2
0
        public void Get_InvalidArgument_ThrowArgumentException6()
        {
            TestingObject <ProductService> testingObject = this.GetTestingObject();
            ProductService prodService = testingObject.GetResolvedTestingObject();

            Assert.Throws <ArgumentException>(() => prodService.Get("", null));
        }
        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));
        }
        public async Task GetAsync_InvalidArgument_ThrowsArgumentException()
        {
            TestingObject <ReportService> testingObject = this.GetTestingObject();

            ReportService reportService = testingObject.GetResolvedTestingObject();

            await Assert.ThrowsAsync <ArgumentException>(async() =>
                                                         await reportService.GetAsync(Guid.Empty));
        }
        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 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));
        }
        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> >()));
        }
Пример #8
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));
        }
        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_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);
        }
Пример #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);
        }