コード例 #1
0
        public async Task WhenUpdatingExistingProduct_ThenReturnsOk()
        {
            CreateProduct             createModel    = ProductModels.GetCreateModel();
            ApiResponse <ViewProduct> createResponse = await _productApiClient.Create(createModel);

            Assert.That(createResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.Created));
            _productIdToDelete = createResponse.Response.Id;

            CreateProduct updateModel = ProductModels.GetCreateModel();

            updateModel.Name = "UpdatedName";
            updateModel.Code = "UpdatedCode";


            ApiResponse <ViewProduct> updateResponse = await _productApiClient.Update(updateModel, createResponse.Response.Id);

            Assert.That(updateResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.OK));


            ApiResponse <ProductDetailsResponse> getResponse = await _productApiClient.Get(createResponse.Response.Id);

            Assert.That(getResponse.Response.Product.Id, Is.EqualTo(createResponse.Response.Id));
            Assert.That(getResponse.Response.Product.Name, Is.EqualTo(updateModel.Name));
            Assert.That(getResponse.Response.Product.Code, Is.EqualTo(updateModel.Code));
        }
コード例 #2
0
        public async Task WhenCreatingProductWithoutName_ThenBadRequestIsReturned()
        {
            CreateProduct productModel = ProductModels.GetCreateModel();

            productModel.Name = string.Empty;

            ApiResponse <ViewProduct> createResponse = await _productApiClient.Create(productModel);

            Assert.That(createResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.IsTrue(createResponse.Response.Errors.Any());
        }
コード例 #3
0
        public async Task WhenCreatingProductWhenPriceNotInRange_ThenBadRequestIsReturned()
        {
            CreateProduct productModel = ProductModels.GetCreateModel();

            productModel.Price = 9999999m;

            ApiResponse <ViewProduct> createResponse = await _productApiClient.Create(productModel);

            Assert.That(createResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.IsTrue(createResponse.Response.Errors.Any());
        }
コード例 #4
0
        public async Task WhenCreatingProductWithInvalidImageExtension_ThenBadRequestIsReturned()
        {
            CreateProduct productModel = ProductModels.GetCreateModel();

            productModel.Photo.Title = "imageWithBadExtension.tif";

            ApiResponse <ViewProduct> apiResponse = await _productApiClient.Create(productModel);

            Assert.That(apiResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.IsTrue(apiResponse.Response.Errors.Any());
        }
コード例 #5
0
        public async Task WhenCreatingProductWithNonUniqueCode_ThenBadRequestIsReturned()
        {
            CreateProduct             productModel = ProductModels.GetCreateModel();
            ApiResponse <ViewProduct> apiResponse  = await _productApiClient.Create(productModel);

            ApiResponse <ViewProduct> createResponse = await _productApiClient.Create(productModel);

            Assert.That(createResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
            Assert.IsTrue(createResponse.Response.Errors.Any());

            _productIdToDelete = apiResponse.Response.Id;
        }
コード例 #6
0
        public async Task WhenUpdatingNonExistingProduct_ThenNewProductIsCreated()
        {
            CreateProduct updateModel          = ProductModels.GetCreateModel();
            int           nonExistingProductId = 9999999;

            ApiResponse <ViewProduct> updateResponse = await _productApiClient.Update(updateModel, nonExistingProductId);

            Assert.That(updateResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.Created));
            Assert.That(updateResponse.Response.Code, Is.EqualTo(updateModel.Code));
            Assert.That(updateResponse.Response.Name, Is.EqualTo(updateModel.Name));
            Assert.That(updateResponse.Response.Price, Is.EqualTo(updateModel.Price));

            _productIdToDelete = updateResponse.Response.Id;
        }
コード例 #7
0
        public async Task WhenExportingProducts_ThenFileIsReturned()
        {
            CreateProduct             upcreateModel  = ProductModels.GetCreateModel();
            ApiResponse <ViewProduct> createResponse = await _productApiClient.Create(upcreateModel);

            ApiResponse <FileExport> exportResponse = await _productApiClient.Export();

            Assert.That(exportResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(exportResponse.Response.Bytes.Length, Is.GreaterThan(0));
            Assert.IsFalse(string.IsNullOrEmpty(exportResponse.Response.FileName));
            Assert.IsFalse(string.IsNullOrEmpty(exportResponse.Response.ContentType));

            _productIdToDelete = createResponse.Response.Id;
        }
コード例 #8
0
        public async Task WhenCreatingProductWithoutImage_ThenCreatedIsReturned()
        {
            CreateProduct productModel = ProductModels.GetCreateModel();

            productModel.Photo = null;

            ApiResponse <ViewProduct> apiResponse = await _productApiClient.Create(productModel);

            Assert.That(apiResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.Created));
            Assert.That(apiResponse.Response.Code, Is.EqualTo(productModel.Code));
            Assert.That(apiResponse.Response.Name, Is.EqualTo(productModel.Name));
            Assert.That(apiResponse.Response.Price, Is.EqualTo(productModel.Price));
            Assert.IsNull(apiResponse.Response.Photo);

            _productIdToDelete = apiResponse.Response.Id;
        }
コード例 #9
0
        public async Task WhenCreatingValidProduct_ThenCreatedIsReturned()
        {
            CreateProduct productModel = ProductModels.GetCreateModel();

            ApiResponse <ViewProduct> apiResponse = await _productApiClient.Create(productModel);

            Assert.That(apiResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.Created));
            Assert.That(apiResponse.Response.Code, Is.EqualTo(productModel.Code));
            Assert.That(apiResponse.Response.Name, Is.EqualTo(productModel.Name));
            Assert.That(apiResponse.Response.Price, Is.EqualTo(productModel.Price));
            Assert.That(apiResponse.Response.Photo.Content, Is.EqualTo(productModel.Photo.Content));
            Assert.That(apiResponse.Response.Photo.ContentType, Is.EqualTo(productModel.Photo.ContentType));
            Assert.That(apiResponse.Response.Photo.Title, Is.EqualTo(productModel.Photo.Title));

            _productIdToDelete = apiResponse.Response.Id;
        }
コード例 #10
0
        public async Task WhenDeletingExistingProduct_ThenNoContentIsReturned()
        {
            ApiResponse <ViewProduct> createResponse = await _productApiClient.Create(ProductModels.GetCreateModel());

            ApiResponse <Response> deleteResponse = await _productApiClient.Delete(createResponse.Response.Id);

            Assert.That(deleteResponse.HttpStatusCode, Is.EqualTo(HttpStatusCode.NoContent));
        }