Exemplo n.º 1
0
        public void ClientCatalogDtoEqualsReturnsCorrectValues()
        {
            ClientCatalogDto c1 = new ClientCatalogDto
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };
            ClientCatalogDto c2 = new ClientCatalogDto
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };
            ClientCatalogDto c3 = new ClientCatalogDto
            {
                Id         = 3,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };
            ClientCatalogDto c4 = new ClientCatalogDto
            {
                Id         = 1,
                Name       = "Client Cat 4",
                InternalId = "CT4"
            };

            Assert.True(c1.Equals(c2));
            Assert.True(c1.Equals(c2, true));
            Assert.False(c1.Equals(c3));
            Assert.False(c1.Equals(c3, true));
            Assert.True(c1.Equals(c4));
            Assert.False(c1.Equals(c4, true));
        }
        public async void PostClientCatalogModelStateErrorReturnsBadRequest()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    controller.ModelState.AddModelError("an error", "some error");
                    ClientCatalogDto p11 = GetTestClientCatalogDto(11);

                    var result = await controller.PostClientCatalog(p11);

                    Assert.IsType <BadRequestObjectResult>(result);
                }
        }
        public async void PostClientCatalogCorrectDataCreatesClientCatalog()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    ClientCatalogDto p11 = GetTestClientCatalogDto(11);

                    var result = await controller.PostClientCatalog(p11);

                    Assert.NotNull(result);
                    var resultValue = Assert.IsType <CreatedAtActionResult>(result);
                }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PostClientCatalog([FromBody] ClientCatalogDto clientCatalog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ClientCatalog clientCatalogReversed = _mapper.Map <ClientCatalog>(clientCatalog);

            _context.ClientCatalogs.Add(clientCatalogReversed);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetClientCatalog", new { id = clientCatalogReversed.Id }, _mapper.Map <ClientCatalogDto>(clientCatalogReversed)));
        }
        public async void DeleteClientCatalogIdDeletesClientCatalog()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    var result = await controller.DeleteClientCatalog(3);

                    ClientCatalogDto p3 = GetTestClientCatalogDto(3);

                    Assert.NotNull(result);
                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.Equal(p3, resultValue);
                }
        }
        public async void GetClientCatalogByIdReturnsSingleClientCatalog()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    var result = await controller.GetClientCatalog(3);

                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;

                    ClientCatalogDto p3 = GetTestClientCatalogDto(3);

                    Assert.NotNull(resultValue);
                    Assert.IsType <ClientCatalogDto>(resultValue);
                    ClientCatalogDto p = (ClientCatalogDto)resultValue;
                    Assert.True(p.Equals(p3));
                    Assert.True(p.Equals(p3, true));
                }
        }
        public void GetClientCatalogsReturnsListOfAuthors()
        {
            using (var context = DbTestContext.GenerateContextWithData())
                using (var controller = new ClientCatalogsController(context, _mapper))
                {
                    var result          = controller.GetClientCatalogs();
                    ClientCatalogDto p3 = GetTestClientCatalogDto(3);

                    var okObjectResult = Assert.IsType <OkObjectResult>(result);
                    var resultValue    = okObjectResult.Value;
                    Assert.IsAssignableFrom <IEnumerable <ClientCatalogDto> >(resultValue);
                    Assert.NotEmpty((IEnumerable <ClientCatalogDto>)resultValue);

                    IEnumerable <ClientCatalogDto> resultValueList = (IEnumerable <ClientCatalogDto>)resultValue;

                    Assert.Equal(10, resultValueList.Count());
                    ClientCatalogDto p = (ClientCatalogDto)resultValueList.Where(r => r.Id == 3).FirstOrDefault();
                    Assert.True(p.Equals(p3));
                    Assert.True(p.Equals(p3, true));
                }
        }
Exemplo n.º 8
0
        public void ClientCatalogProperlyMappedToClientCatalogDto()
        {
            ClientCatalogDto cDto1 = new ClientCatalogDto
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };
            ClientCatalog c1 = new ClientCatalog
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };

            ClientCatalogDto cDto2 = _mapper.Map <ClientCatalogDto>(c1);

            Assert.NotNull(cDto2);
            Assert.True(cDto1.Equals(cDto2));
            Assert.True(cDto1.Equals(cDto2, true));
        }
Exemplo n.º 9
0
        public void ClientCatalogDtoProperlyReversedToClientCatalog()
        {
            ClientCatalogDto cDto1 = new ClientCatalogDto
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };
            ClientCatalog c1 = new ClientCatalog
            {
                Id         = 1,
                Name       = "Client Cat 1",
                InternalId = "CT1"
            };

            ClientCatalog c2 = _mapper.Map <ClientCatalog>(cDto1);

            Assert.NotNull(c2);
            Assert.True(c1.Equals(c2));
            Assert.True(c1.Equals(c2, true));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> PutClientCatalog([FromRoute] int id, [FromBody] ClientCatalogDto clientCatalog)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != clientCatalog.Id)
            {
                ModelState.AddModelError("Invalid Catalog ID", "The Catalog ID supplied in the query and the body of the request do not match.");
                return(BadRequest(ModelState));
            }

            ClientCatalog clientCatalogReversed = _mapper.Map <ClientCatalog>(clientCatalog);

            _context.Entry(clientCatalogReversed).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException xcp)
            {
                if (!ClientCatalogExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    ModelState.AddModelError("Error", xcp.ToString());
                    return(BadRequest(ModelState));
                }
            }

            return(NoContent());
        }