Exemplo n.º 1
0
        public void ApoDivisionServiceShouldReturnCorrectValueWhenUpdateSameValueToSameId()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var editApo = new ApoDivisionForCreateOrEdit()
            {
                Name = "Food",
            };

            var sut = service.Edit(0, editApo);

            Assert.Equal(sut.Id, 0);
            AssertObjects.PropertyValuesAreEquals(sut, Mapper.Map <ApoDivisionDto>(_apoDivision.Single(x => x.Id == 0)));
        }
Exemplo n.º 2
0
        public void ApoDivisionServiceShouldReturnCorrectValueWhenEditSuccess()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var editApo = new ApoDivisionForCreateOrEdit()
            {
                Name = "FOOD EDIT",
            };

            var sut = service.Edit(0, editApo);

            Assert.Equal(sut.Id, 0);
            Assert.Equal(sut.Name, "FOOD EDIT");
        }
Exemplo n.º 3
0
        public void ApoDivisionShouldReturnCorrectvaluewhenSearchByName()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var searchObj = new ApoDivisionForCreateOrEdit()
            {
                Name = "Food"
            };

            var sut = service.GetByName(searchObj);

            var shouldEqual = _apoDivision.Single(x => x.Name.Equals(searchObj.Name));


            AssertObjects.PropertyValuesAreEquals(sut, Mapper.Map <ApoDivisionDto>(shouldEqual));
        }
Exemplo n.º 4
0
        public void ApoDivisonServiceShouldReturnNullWhenUpdateDuplicateValueButNotOwnId()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var editApo = new ApoDivisionForCreateOrEdit()
            {
                Name = "FOOD",
            };


            var exception = Record.Exception(() => service.Edit(10, editApo));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
            Assert.True(exception.Message.Contains($"Name {editApo.Name} is Already exist."));
        }
Exemplo n.º 5
0
        public void ApoDivisionServiceShouldReturnNullWhenNameIsAlreadyExist()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var newApo = new ApoDivisionForCreateOrEdit()
            {
                Name = "food"
            };



            var exception = Record.Exception(() => service.Create(newApo));

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
            Assert.True(exception.Message.Contains($"Name {newApo.Name} is Already exist."));
        }
Exemplo n.º 6
0
        public HttpResponseMessage Update(int id, [FromBody] ApoDivisionForCreateOrEdit apoDivisionForCreateOrEdit)
        {
            try
            {
                var updateApo = _apoDivisionService.Edit(id, apoDivisionForCreateOrEdit as IApoDivisionForCreateOrEdit);

                if (updateApo != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, updateApo));
                }

                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
            catch (ArgumentException e)
            {
                HttpError err = new HttpError(e.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, err));
            }
        }
Exemplo n.º 7
0
        public HttpResponseMessage Post([FromBody] ApoDivisionForCreateOrEdit apoDivisionForCreateOrEdit)
        {
            try
            {
                var createdApo = _apoDivisionService.Create(apoDivisionForCreateOrEdit);

                if (createdApo != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, createdApo));
                }

                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
            catch (ArgumentException e)
            {
                HttpError err = new HttpError(e.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, err));
            }
        }
Exemplo n.º 8
0
        public void ApoDivisionServiceShouldReturnNewElementWhenCreateSuccess()
        {
            var service = new ApoDivisionService(_apoDivisionRepository, _apoGroupService);

            var newApo = new ApoDivisionForCreateOrEdit()
            {
                Name = "New Apo"
            };


            var nextCode           = (Convert.ToInt32(_apoDivision.Last().Code) + 1).ToString("D2");
            var compareEqualObject = Mapper.Map <ApoDivisionDto>(newApo);

            compareEqualObject.Code = nextCode;
            compareEqualObject.Id   = _apoDivision.Last().Id + 1;

            var sut = service.Create(newApo);

            Assert.Equal(sut.Id, _apoDivision.Last().Id + 1);
            AssertObjects.PropertyValuesAreEquals(sut, compareEqualObject);
        }