private static async Task DoWork(SampleContext inputContext, SampleContext outputContext, Stopwatch doworkWatch)
        {
            doworkWatch.Start();
            using (inputContext)
            {
                using (outputContext)
                {
                    using (PostService svc = new PostService(inputContext))
                    {
                        svc.CreateNewPost(1, "sampleSubject", "sampleBody");
                        //svc.DeletPostWithId(2);
                        //svc.CreateNewPost(1, "sampleSubject", "sampleBody");

                        var allPosts = svc.GetAllPost().ToList();

                        allPosts.Count.ShouldBe(2);

                        var result = await inputContext.CompareTo(outputContext);

                        result.AreEqual.ShouldBe(true, result.ToString());
                    }
                }
            }
            doworkWatch.Stop();
        }
Beispiel #2
0
        public async Task ShouldReturnFalseForContextWithEntryContainingDifferentValues()
        {
            XmlFileContext <SampleContext> xmlFileCtx         = new XmlFileContext <SampleContext>(this.GetType());
            XmlFileContext <SampleContext> xmlFileExpectedCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test2");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test2");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
            result.Differences.Count.ShouldBe(2);

            result.Differences[0].ObjectId.ShouldBe("2");
            result.Differences[0].ObjectName.ShouldBe("Post");
            result.Differences[0].PropertyName.ShouldBe("Subject");
            result.Differences[0].ActualPropertyContent.ShouldBe("First Text");
            result.Differences[0].ExpectedPropertyContent.ShouldBe("First Text Modified");
            result.Differences[0].ToString().ShouldBe("Post.Subject Should be [First Text Modified] but was [First Text] - object with Post_Id : 2");

            result.Differences[1].ObjectId.ShouldBe("2");
            result.Differences[1].ObjectName.ShouldBe("Post");
            result.Differences[1].PropertyName.ShouldBe("Body");
            result.Differences[1].ActualPropertyContent.ShouldBe("Some Text here");
            result.Differences[1].ExpectedPropertyContent.ShouldBe("Some Other Text here");
        }
Beispiel #3
0
        public async Task ShouldReturnTrueForSameContextComparison()
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test1");
            SampleContext ctx2 = xmlFileCtx.InputContext("test1");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(true);
        }
Beispiel #4
0
        public async Task ShouldBeFalseWhenEntityStateAreDifferent()
        {
            XmlFileContext <SampleContext> xmlFileCtx         = new XmlFileContext <SampleContext>(this.GetType());
            XmlFileContext <SampleContext> xmlFileExpectedCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test4");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test4");
            SampleContext ctx3 = xmlFileExpectedCtx.ExpectedContext("test4b");

            var auth = ctx1.Authors.Find((Int64)1);

            auth.FirstName = "cedric";

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false, result.ToString());

            ctx1.SaveChanges();
            result = await ctx1.CompareTo(ctx3);

            result.AreEqual.ShouldBe(true, result.ToString());
        }
Beispiel #5
0
        public async Task ShouldReturnFalseForContextWithMissingEntryinExpected()
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            XmlFileContext <SampleContext> xmlFileExpectedCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test1");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test1");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
        }
Beispiel #6
0
        public async Task ShouldDeleteAuthor(string test, Int64 autId)
        {
            using (SampleContext ctx = GetInputContext(test))
            {
                using (PostService svc = new PostService(ctx))
                {
                    svc.DeleteAuthor(autId);

                    var result = await ctx.CompareTo(GetExpectedContext(test));

                    result.AreEqual.ShouldBe(true, result.ToString());
                }
            }
        }
Beispiel #7
0
        public async Task Should_CreateNewPost(string test, Int64 actorId, string postsubject, string postBody)
        {
            using (SampleContext ctx = GetInputContext(test))
            {
                using (PostService svc = new PostService(ctx))
                {
                    svc.CreateNewPost(actorId, postsubject, postBody);

                    var result = await ctx.CompareTo(GetExpectedContext(test));

                    result.AreEqual.ShouldBe(true, result.ToString());
                }
            }
        }
        public async Task Should_Delete_Post()
        {
            using (SampleContext ctx = GetInputContext("test1"))
            {
                using (Service svc = new Service(ctx))
                {
                    svc.DeletPostWithId(1);

                    var result = await ctx.CompareTo(GetExpectedContext("test1"));

                    result.AreEqual.ShouldBe(true, result.ToString());
                }
            }
        }
Beispiel #9
0
        public async Task ShouldReturnFalseForContextWithSameCollectionCountButDifferentIds()
        {
            XmlFileContext <SampleContext> xmlFileCtx = new XmlFileContext <SampleContext>(this.GetType());

            XmlFileContext <SampleContext> xmlFileExpectedCtx = new XmlFileContext <SampleContext>(this.GetType());

            SampleContext ctx1 = xmlFileCtx.InputContext("test3");
            SampleContext ctx2 = xmlFileExpectedCtx.ExpectedContext("test3");

            var result = await ctx1.CompareTo(ctx2);

            result.AreEqual.ShouldBe(false);
            result.Differences.Count.ShouldBe(1);
            result.Differences[0].ToString().ShouldBe("Author was null - object with AUT_ID : 2 (we couldn't find an actual object with expected id  : 2 - this can be caused because the id is auto generated. You could adapt the ids of the expected object)");
        }
Beispiel #10
0
        public async Task Should_CreateTwoPostAndDeleteOne()
        {
            string test = "test31";

            using (SampleContext ctx = GetInputContext(test))
            {
                using (PostService svc = new PostService(ctx))
                {
                    svc.CreateNewPost(3, "NewPost Created1", "NewPost Created1");
                    svc.DeletPostWithId(3);
                    svc.CreateNewPost(2, "NewPost Created2", "NewPost Created2");

                    var result = await ctx.CompareTo(GetExpectedContext(test));

                    result.AreEqual.ShouldBe(true, result.ToString());
                }
            }
        }
        public async Task Should_Add_Post_And_Author()
        {
            using (SampleContext ctx = GetInputContext("test2"))
            {
                using (Service svc = new Service(ctx))
                {
                    Post   p = new Post();
                    Author a = new Author()
                    {
                        FirstName = "test"
                    };
                    p.Author = a;
                    ctx.Posts.Add(p);

                    ctx.SaveChanges();

                    var result = await ctx.CompareTo(GetExpectedContext("test2"));


                    result.AreEqual.ShouldBe(true, result.ToString());
                }
            }
        }
        public async Task ShouldRecordOriginalValues(string test)
        {
            var contextFactory = new XmlFileContext <SampleContext>(this.GetType());

            using (SampleContext sampleContext = contextFactory.InputContext(test, "original-values-tests", false).StartRecordingOriginalValues())
            {
                Post post = sampleContext.Posts.Find((Int64)1);
                post.Body = "Changed : " + post.Body;
                sampleContext.SaveChanges();

                var recordedContext = sampleContext.GetRecordedContext();

                sampleContext.PauseRecordingOriginalValues();

                var result = await sampleContext.CompareTo(recordedContext);

                result.AreEqual.ShouldBe(false);
                result.Differences.Count.ShouldBe(1);
                result.Differences[0].ToString().ShouldBe("Post.Body Should be [Original Body] but was [Changed : Original Body] - object with Post_Id : 1");

                sampleContext.StopRecordingOriginalValues();
            }
        }
        private static async Task DoWork(SampleContext inputContext, SampleContext outputContext, Stopwatch doworkWatch)
        {
            doworkWatch.Start();
            using (inputContext)
            {
                using (outputContext)
                {
                    using (PostService svc = new PostService(inputContext))
                    {
                        svc.CreateNewPost(1, "sampleSubject", "sampleBody");
                        //svc.DeletPostWithId(2);
                        //svc.CreateNewPost(1, "sampleSubject", "sampleBody");

                        var allPosts = svc.GetAllPost().ToList();

                        allPosts.Count.ShouldBe(2);

                        var result = await inputContext.CompareTo(outputContext);

                        result.AreEqual.ShouldBe(true, result.ToString());
                    }
                }
            }
            doworkWatch.Stop();
        }