Ejemplo n.º 1
0
        public async Task should_update_item()
        {
            var testItem = new Item
            {
                Id          = new Guid("b5b05534-9263-448c-a69e-0bbd8b3eb90e"),
                Name        = "Test album",
                Description = "Description updated",
                LabelName   = "Label name",
                Price       = new Price {
                    Amount = 50, Currency = "EUR"
                },
                PictureUri     = "https://mycdn.com/pictures/32423423",
                ReleaseDate    = DateTimeOffset.Now,
                AvailableStock = 6,
                GenreId        = new Guid("c04f05c0-f6ad-44d1-a400-3375bfb5dfd6"),
                ArtistId       = new Guid("f08a333d-30db-4dd1-b8ba-3b0473c7cdab")
            };

            var options = new DbContextOptionsBuilder <CatalogContext>()
                          .UseInMemoryDatabase("should_update_item")
                          .Options;

            await using var context = new TestCatalogContext(options);
            context.Database.EnsureCreated();

            var sut = new ItemRepository(context);

            sut.Update(testItem);

            await sut.UnitOfWork.SaveEntitiesAsync();

            context.Items
            .FirstOrDefault(x => x.Id == testItem.Id)
            ?.Description.ShouldBe("Description updated");
        }
Ejemplo n.º 2
0
        public async Task should_returns_null_with_id_not_present()
        {
            var optionsBuilder = new DbContextOptionsBuilder <CatalogContext>()
                                 .UseInMemoryDatabase("should_returns_null_with_id_not_present");

            await using var context = new TestCatalogContext(optionsBuilder.Options);
            context.Database.EnsureCreated();
            var itemRepo = new ItemRepository(context);
            var item     = await itemRepo.GetAsync(Guid.NewGuid());

            item.ShouldBeNull();
        }
Ejemplo n.º 3
0
        public async Task should_get_data()
        {
            var optionsBuilder = new DbContextOptionsBuilder <CatalogContext>()
                                 .UseInMemoryDatabase("test");

            await using var context = new TestCatalogContext(optionsBuilder.Options);
            context.Database.EnsureCreated();
            var itemRepo = new ItemRepository(context);
            var result   = await itemRepo.GetAsync();

            result.ShouldNotBeNull();
        }
        public async Task should_return_record_by_id(string guid)
        {
            var options = new DbContextOptionsBuilder <CatalogContext>()
                          .UseInMemoryDatabase(databaseName: "should_return_record_by_id")
                          .Options;

            await using var context = new TestCatalogContext(options);
            context.Database.EnsureCreated();

            var sut    = new ItemRepository(context);
            var result = await sut.GetAsync(new Guid(guid));

            result.Id.ShouldBe(new Guid(guid));
        }
        public async Task should_returns_null_with_id_not_present()
        {
            var options = new DbContextOptionsBuilder <CatalogContext>()
                          .UseInMemoryDatabase(databaseName: "should_returns_null_with_id_not_present")
                          .Options;

            await using var context = new TestCatalogContext(options);
            context.Database.EnsureCreated();

            var sut    = new ItemRepository(context);
            var result = await sut.GetAsync(Guid.NewGuid());

            result.ShouldBeNull();
        }
        public async Task should_get_data()
        {
            var options = new DbContextOptionsBuilder <CatalogContext>()
                          .UseInMemoryDatabase(databaseName: "should_get_data")
                          .Options;

            await using var context = new TestCatalogContext(options);
            context.Database.EnsureCreated();

            var sut    = new ItemRepository(context);
            var result = await sut.GetAsync();

            result
            .Count
            .ShouldBe(4);
        }
        public async Task should_update_item(string jsonEntity)
        {
            var entity = JsonConvert.DeserializeObject <Item>(jsonEntity);

            entity.Description = "Updated";

            var options = new DbContextOptionsBuilder <CatalogContext>()
                          .UseInMemoryDatabase(databaseName: "should_update_item")
                          .Options;

            await using var context = new TestCatalogContext(options);
            context.Database.EnsureCreated();
            var sut = new ItemRepository(context);

            sut.Update(entity);
            await sut.UnitOfWork.SaveEntitiesAsync();

            context.Items
            .FirstOrDefault(_ => _.Id == entity.Id)
            ?.Description.ShouldBe("Updated");
        }
Ejemplo n.º 8
0
        public async Task should_add_new_item(string jsonEntity)
        {
            var entity = JsonConvert.DeserializeObject <Item>(jsonEntity);

            var options = new DbContextOptionsBuilder <CatalogContext>()
                          .UseInMemoryDatabase(databaseName: "should_add_new_items")
                          .Options;

            await using var context = new TestCatalogContext(options);
            context.Database.EnsureCreated();

            var sut = new ItemRepository(context);

            sut.Add(entity);

            await sut.UnitOfWork.SaveEntitiesAsync();

            context.Items
            .FirstOrDefault(x => x.Id == entity.Id)
            .ShouldNotBeNull();
        }
Ejemplo n.º 9
0
 public ItemRepositoryTests(CatalogContextFactory catalogContextFactory)
 {
     _context = catalogContextFactory.ContextInstance;
     _sut     = new ItemRepository(_context);
 }