Example #1
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_InvalidArgument_ThrowArgumentException()
        {
            TestingObject <ProductRepository> testingObject = this.GetTestingObject();
            ProductRepository prodRepository = testingObject.GetResolvedTestingObject();

            Assert.Throws <ArgumentException>(() => prodRepository.Find(null));
        }
Example #3
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);
        }
Example #4
0
        private TestingObject <ProductService> GetTestingObject()
        {
            var testingObject = new TestingObject <ProductService>();

            testingObject.AddDependency(new Mock <IProductRepository>(MockBehavior.Loose));
            return(testingObject);
        }
        private TestingObject <R> GetTestingObject <R, D>() where R : class
        {
            var testingObject = new TestingObject <R>();

            testingObject.AddDependency(new Mock <IDataContext <D> >(MockBehavior.Strict));
            return(testingObject);
        }
Example #6
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));
        }
        private TestingObject <UserService> GetTestingObject()
        {
            var testingObject = new TestingObject <UserService>();

            testingObject.AddDependency(new Mock <IDatabaseContext>(MockBehavior.Strict));
            return(testingObject);
        }
Example #9
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 = "******" });
        }
        private TestingObject <ProductRepository> GetTestingObject()
        {
            var testingObject = new TestingObject <ProductRepository>();

            testingObject.AddDependency(new Mock <IDataContext <Product> >(MockBehavior.Loose));
            testingObject.AddDependency(new Mock <IProductCommand <Product, bool> >(MockBehavior.Loose));
            return(testingObject);
        }
Example #11
0
        public void TestWriteFields()
        {
            var target = new TestingObject {
                ThisShouldHaveBeenAProperty = "FooBar"
            };

            Approvals.Verify(target.WriteFieldsToString());
        }
Example #12
0
        public void WriteOnlyPropertyTest()
        {
            var target = new TestingObject {
                WriteOnlyString = "Hello", ReadWriteInt = 10
            };

            Approvals.Verify(target.WritePropertiesToString());
        }
        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> >()));
        }
        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));
        }
Example #18
0
        public void Object_Serializes_To_XmlString()
        {
            var testObject = new TestingObject();
            string testString;

            using (var writer = new StringWriter())
            {
                var serializer = new XmlSerializer(testObject.GetType());

                serializer.Serialize(writer, testObject);

                testString = writer.ToString();
            }

            // Code Under Test
            var xmlString = XmlHelper.SerializeToXmlString(testObject);

            Assert.AreEqual(testString, xmlString);
        }
        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);
        }
        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);
        }
		public void TestWriteFields()
		{
			var target = new TestingObject() {ThisShouldHaveBeenAProperty = "FooBar"};
			Approvals.Verify(target.WriteFieldsToString());
		}
		public void WriteOnlyPropertyTest()
		{
			var target = new TestingObject() {WriteOnlyString = "Hello", ReadWriteInt = 10};
			Approvals.Verify(target.WritePropertiesToString());
		}