Ejemplo n.º 1
0
        public async Task UpdateModel(
            EStatusCode expectedStatus,
            UpdateModel mutation,
            bool?withModel = false,
            bool?withBrand = false
            )
        {
            if (withBrand.Value)
            {
                EntitiesFactory.NewBrand(id: mutation.BrandId).Save();
            }
            if (withModel.Value)
            {
                EntitiesFactory.NewModel(id: mutation.Id, name: mutation.Name).Save();
            }
            if (expectedStatus == EStatusCode.Conflict)
            {
                EntitiesFactory.NewModel(name: mutation.Name).Save();
            }

            var result = await MutationsHandler.Handle(mutation);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == EStatusCode.Success)
            {
                var modelDb = await MutationsDbContext.Models.FindAsync(mutation.Id);

                Assert.Equal(mutation.Name, modelDb.Name);
                Assert.Equal(mutation.BrandId, modelDb.BrandId);
            }
        }
Ejemplo n.º 2
0
        public async void ListBrands(
            EStatusCode expectedStatus,
            ListBrands query
            )
        {
            var brand = EntitiesFactory.NewBrand().Save();

            var(status, result) = await Request.Get <QueryResultListTest <BrandList> >(Uri, query);

            Assert.Equal(expectedStatus, status);
            if (expectedStatus == EStatusCode.Success)
            {
                Assert.NotEmpty(result.Data);
                Assert.Contains(result.Data, d => d.Id == brand.Id);
            }
        }
Ejemplo n.º 3
0
        public async Task DeleteBrand(
            EStatusCode expectedStatus,
            DeleteBrand mutation
            )
        {
            if (expectedStatus != EStatusCode.NotFound)
            {
                EntitiesFactory.NewBrand(id: mutation.Id).Save();
            }

            var result = await MutationsHandler.Handle(mutation);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == EStatusCode.Success)
            {
                var exists = await MutationsDbContext.Brands.AnyAsync(b => b.Id == mutation.Id);

                Assert.False(exists);
            }
        }
Ejemplo n.º 4
0
        public async Task CreateBrand(
            EStatusCode expectedStatus,
            CreateBrand mutation
            )
        {
            if (expectedStatus == EStatusCode.Conflict)
            {
                EntitiesFactory.NewBrand(name: mutation.Name).Save();
            }

            var result = await MutationsHandler.Handle(mutation);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == EStatusCode.Success)
            {
                var brandDb = await MutationsDbContext.Brands.Where(b => b.Id == mutation.Id).FirstOrDefaultAsync();

                Assert.NotNull(brandDb);
                Assert.Equal(mutation.Name, brandDb.Name);
            }
        }
Ejemplo n.º 5
0
        public async void GetBrad(
            EStatusCode expectedStatus,
            GetBrand query
            )
        {
            var brand = null as Brand;

            if (expectedStatus != EStatusCode.NotFound)
            {
                brand = EntitiesFactory.NewBrand(id: query.Id).Save();
            }
            var(status, result) = await Request.Get <QueryResultOneTest <BrandDetail> >(new Uri($"{Uri}/{query.Id}"), query);

            Assert.Equal(expectedStatus, status);
            if (expectedStatus == EStatusCode.Success)
            {
                var brandResult = result.Data;
                Assert.NotNull(brandResult);
                Assert.Equal(brand.Id, brandResult.Id);
                Assert.Equal(brand.Name, brandResult.Name);
            }
        }
Ejemplo n.º 6
0
        public async Task CreateModel(
            EStatusCode expectedStatus,
            CreateModel mutation
            )
        {
            if (expectedStatus != EStatusCode.NotFound)
            {
                EntitiesFactory.NewBrand(id: mutation.BrandId).Save();
            }
            if (expectedStatus == EStatusCode.Conflict)
            {
                EntitiesFactory.NewModel(name: mutation.Name).Save();
            }

            var result = await MutationsHandler.Handle(mutation);

            Assert.Equal(expectedStatus, result.Status);
            if (expectedStatus == EStatusCode.Success)
            {
                var modelDb = await MutationsDbContext.Models.FindAsync(mutation.Id);

                Assert.Equal(mutation.Name, modelDb.Name);
            }
        }