コード例 #1
0
        public async Task <IActionResult> AddRowCategoryAsync(RowCategoryDto rowCategory)
        {
            Logger.Here().Info("{AddRowCategoryAsync} - {rowCategory}", nameof(AddRowCategoryAsync), rowCategory.Id);
            var result = await _service.CreateInfrastructureService().AddRowCategoryAsync(rowCategory);

            return(GetCreatedStatus(result, nameof(GetRowCategoryAsync), "Given row category is not addable."));
        }
コード例 #2
0
        public async Task <RowCategoryDto> UpdateRowCategoryAsync(RowCategoryDto categoryDto)
        {
            ValidateNull(Logger.Here(), categoryDto);
            var category = Map(categoryDto);

            return((await _unitOfWork.RepositoryInfrastructure.UpdateRowCategoryAsync(category)) > 0
                ? categoryDto
                : null);
        }
コード例 #3
0
        public async Task <RowCategoryDto> AddRowCategoryAsync(RowCategoryDto category)
        {
            ValidateNull(Logger.Here(), category);
            var newId = await _unitOfWork.RepositoryInfrastructure.AddRowCategoryAsync(Map(category));

            if (newId > 0L)
            {
                category.Id = newId;
            }

            return(newId > 0L ? category : null);
        }
コード例 #4
0
        public async Task <IActionResult> UpdateRowCategory(RowCategoryDto rowCategory)
        {
            var infrastructureService = _service.CreateInfrastructureService();

            Logger.Here().Info(nameof(UpdateRowCategory));
            if (!await infrastructureService.RowCategoryExistAsync(rowCategory.Id))
            {
                Logger.Here().Error("{UpdateRowCategory} - {Id} not exist", nameof(UpdateRowCategory), rowCategory.Id);
                return(BadRequestResponse("Given row category do not exist"));
            }

            var result = await infrastructureService.UpdateRowCategoryAsync(rowCategory);

            return(GetUpdatedStatus(result, "Given row category is not updateable."));
        }
コード例 #5
0
ファイル: ManageRowsTest.cs プロジェクト: EnvyIT/apollo
        public async Task Test_Workflow_RowCategory_Valid()
        {
            Logger.Info("Load row categories ...");
            var response = await Get(BaseUrl, EndpointCategories);

            await CheckResponseAndLogStatusCodeAsync(Logger, response);

            var categories = JsonConvert.DeserializeObject <IEnumerable <RowCategoryDto> >(
                await response.Content.ReadAsStringAsync()
                ).ToList();

            categories.Should().HaveCount(DataSeeder.RowCategories.Count);
            Logger.Info(categories.ToPrettyString());

            var newCategory = new RowCategoryDto {
                Name = "New Category", PriceFactor = 1.85
            };
            var updateCategoryReferences =
                categories.First(c => DataSeeder.Rows.Select(r => r.CategoryId).Contains(c.Id));

            updateCategoryReferences.PriceFactor = 2.0;
            var updateCategory = categories.First(c => !DataSeeder.Rows.Select(r => r.CategoryId).Contains(c.Id));

            updateCategory.Name = "Updated category";
            var deleteCategoryReferences = categories
                                           .Last(c => DataSeeder.Rows.Select(r => r.CategoryId).Contains(c.Id))
                                           .Id;
            var deletedCategory = categories
                                  .Last(c => !DataSeeder.Rows.Select(r => r.CategoryId).Contains(c.Id))
                                  .Id;

            await Authenticate(AdminUser, AdminPassword);

            Logger.Info($"Add new row category: {newCategory.ToPrettyString()} ...");
            response = await Post(BaseUrl, EndpointCategory, newCategory);
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.Created);

            var newId = await GetCreatedIdAsync(response);

            Logger.Info(
                $"Update row category with referenced seats: {updateCategoryReferences.ToPrettyString()} ...");
            response = await Put(BaseUrl, EndpointCategory, updateCategoryReferences);
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.NoContent);

            Logger.Info($"Update row category: ${updateCategory.ToPrettyString()} ...");
            response = await Put(BaseUrl, EndpointCategory, updateCategory);
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.NoContent);

            Logger.Info(
                $"Try delete row category with referenced seats: {deleteCategoryReferences} ...");
            response = await Delete(BaseUrl, $"{EndpointCategory}/{deleteCategoryReferences}");
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.BadRequest);

            Logger.Info($"Delete cinema hall: {deletedCategory} ...");
            response = await Delete(BaseUrl, $"{EndpointCategory}/{deletedCategory}");
            await CheckResponseAndLogStatusCodeAsync(Logger, response, HttpStatusCode.NoContent);

            Logger.Info("Load row categories ...");
            response = await Get(BaseUrl, EndpointCategories);
            await CheckResponseAndLogStatusCodeAsync(Logger, response);

            categories = JsonConvert.DeserializeObject <IEnumerable <RowCategoryDto> >(
                await response.Content.ReadAsStringAsync()
                ).ToList();

            var rowCategoryIds = categories.Select(g => g.Id).ToList();

            rowCategoryIds.Should().Contain(newId);
            rowCategoryIds.Should().Contain(updateCategoryReferences.Id);
            rowCategoryIds.Should().Contain(updateCategory.Id);
            rowCategoryIds.Should().Contain(deleteCategoryReferences);
            rowCategoryIds.Should().NotContain(deletedCategory);

            categories.First(g => g.Id == newId).Name.Should().Be(newCategory.Name);
            categories.First(g => g.Id == updateCategory.Id).Name.Should().Be(updateCategory.Name);
            categories.First(g => g.Id == updateCategoryReferences.Id).PriceFactor.Should()
            .Be(updateCategoryReferences.PriceFactor);

            Logger.Info(categories.ToPrettyString());
        }