Ejemplo n.º 1
0
        public void Can_remove_item_and_all_associated_tags()
        {
            using (var context = new ItemsContext(ContextOptions))
            {
                var controller = new ItemsController(context);

                var item = controller.DeleteItem("ItemThree").Value;

                Assert.Equal("ItemThree", item.Name);
            }

            using (var context = new ItemsContext(ContextOptions))
            {
                Assert.False(context.Set <Item>().Any(e => e.Name == "ItemThree"));
                Assert.False(context.Set <Tag>().Any(e => e.Label.StartsWith("Tag3")));
            }
        }
Ejemplo n.º 2
0
        public void Can_add_item_differing_only_by_case()
        {
            using (var context = new ItemsContext(ContextOptions))
            {
                var controller = new ItemsController(context);

                var item = controller.PostItem("itemtwo").Value;

                Assert.Equal("itemtwo", item.Name);
            }

            using (var context = new ItemsContext(ContextOptions))
            {
                var item = context.Set <Item>().Single(e => e.Name == "itemtwo");

                Assert.Equal(0, item.Tags.Count);
            }
        }
Ejemplo n.º 3
0
        public void Can_add_item()
        {
            using (var context = new ItemsContext(ContextOptions))
            {
                var controller = new ItemsController(context);

                var item = controller.PostItem("ItemFour").Value;

                Assert.Equal("ItemFour", item.Name);
            }

            using (var context = new ItemsContext(ContextOptions))
            {
                var item = context.Set <Item>().Single(e => e.Name == "ItemFour");

                Assert.Equal("ItemFour", item.Name);
                Assert.Equal(0, item.Tags.Count);
            }
        }
Ejemplo n.º 4
0
        public void Can_add_tag()
        {
            using (var context = new ItemsContext(ContextOptions))
            {
                var controller = new ItemsController(context);

                var tag = controller.PostTag("ItemTwo", "Tag21").Value;

                Assert.Equal("Tag21", tag.Label);
                Assert.Equal(1, tag.Count);
            }

            using (var context = new ItemsContext(ContextOptions))
            {
                var item = context.Set <Item>().Include(e => e.Tags).Single(e => e.Name == "ItemTwo");

                Assert.Equal(1, item.Tags.Count);
                Assert.Equal("Tag21", item.Tags[0].Label);
                Assert.Equal(1, item.Tags[0].Count);
            }
        }
Ejemplo n.º 5
0
        public void Can_add_tag_when_already_existing_tag()
        {
            using (var context = new ItemsContext(ContextOptions))
            {
                var controller = new ItemsController(context);

                var tag = controller.PostTag("ItemThree", "Tag32").Value;

                Assert.Equal("Tag32", tag.Label);
                Assert.Equal(3, tag.Count);
            }

            using (var context = new ItemsContext(ContextOptions))
            {
                var item = context.Set <Item>().Include(e => e.Tags).Single(e => e.Name == "ItemThree");

                Assert.Equal(2, item.Tags.Count);
                Assert.Equal("Tag31", item.Tags[0].Label);
                Assert.Equal(3, item.Tags[0].Count);
                Assert.Equal("Tag32", item.Tags[1].Label);
                Assert.Equal(3, item.Tags[1].Count);
            }
        }
        public void EntityFrameworkContextEventsInstrumentedTest()
        {
            var activityProcessor = new Mock <BaseProcessor <Activity> >();

            using var shutdownSignal = Sdk.CreateTracerProviderBuilder()
                                       .AddProcessor(activityProcessor.Object)
                                       .AddEntityFrameworkCoreInstrumentation().Build();

            using (var context = new ItemsContext(this.contextOptions))
            {
                var items = context.Set <Item>().OrderBy(e => e.Name).ToList();

                Assert.Equal(3, items.Count);
                Assert.Equal("ItemOne", items[0].Name);
                Assert.Equal("ItemThree", items[1].Name);
                Assert.Equal("ItemTwo", items[2].Name);
            }

            Assert.Equal(3, activityProcessor.Invocations.Count);

            var activity = (Activity)activityProcessor.Invocations[1].Arguments[0];

            VerifyActivityData(activity);
        }
Ejemplo n.º 7
0
 public T Create(T entity)
 {
     return(_context.Set <T>().Add(entity).Entity);
 }