Ejemplo n.º 1
0
        public void ApoGroupShouldReturnTrueWhenDelteSuccess()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var sut = service.Delete(0);

            Assert.True(sut);
        }
Ejemplo n.º 2
0
        public void ApoGroupShouldReturnFalseWhenDeleteFailed()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var sut = service.Delete(150);

            Assert.False(sut);
        }
Ejemplo n.º 3
0
        public void ApoGroupShouldReturnNullWhenIdIsNotExistInDatabase()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var sut = service.GetById(100);

            Assert.Null(sut);
        }
Ejemplo n.º 4
0
        public void ApoGroupServiceShouldReturnAllItem()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var sut = service.GetAll();

            Assert.IsType <List <ApoGroupDto> >(sut);
            Assert.Equal(sut.Count(), _apoGroup.Count());
        }
Ejemplo n.º 5
0
        public void ApoGroupReturnNullWhenGivenNoExistValue()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var parameter = new ApoGroupResourceParameter(1, 5, 1, "Tobacasdasdco");

            var sut = service.GetAll(parameter);

            Assert.True(!sut.List.Any());
        }
Ejemplo n.º 6
0
        public void ApoGroupReturnCorrectValueWhenSearchText()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var parameter = new ApoGroupResourceParameter(1, 5, 1, "Tobacco");

            var sut = service.GetAll(parameter);

            Assert.True(sut.List.All(x => x.Name.ToLowerInvariant().Contains(parameter.SearchText.ToLowerInvariant()) ||
                                     x.Code.ToLowerInvariant().Contains(parameter.SearchText.ToLowerInvariant())));
        }
Ejemplo n.º 7
0
        public void ApoGroupReturnCorrectObjectWhenAssignCorrectId()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);


            var sut = service.GetById(10);

            var compareObj = Mapper.Map <ApoGroupDto>(_apoGroup.Single(x => x.Id == 10));

            compareObj.DivisionName = _apoDivision.Single(x => x.Id == compareObj.DivisionId).Name;

            AssertObjects.PropertyValuesAreEquals(sut, compareObj);
        }
Ejemplo n.º 8
0
        public void ApoGroupServiceShouldReturnCorrectValueWhenEditSuccess()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var updateApo = new ApoGroupForCreateOrUpdate()
            {
                Name = "Packaged -- new",
            };

            var sut = service.Edit(1, updateApo);

            Assert.Equal(sut.Name, "Packaged -- new");
            Assert.Equal(sut.Id, 1);
        }
Ejemplo n.º 9
0
        public void ApoGroupServiceShouldReturnNullWhenUpdateDuplicateValueButNotOwnId()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var editApo = new ApoGroupForCreateOrUpdate()
            {
                Name = "Packaged",
            };


            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."));
        }
Ejemplo n.º 10
0
        public void ApoGroupSouldReturnErrorWhenCreateAlreadyExistValue()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var createdApoGroup = new ApoGroupForCreateOrUpdate()
            {
                Name = "Packaged",
            };


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

            Assert.NotNull(exception);
            Assert.IsType <ArgumentException>(exception);
            Assert.True(exception.Message.Contains($"Name {createdApoGroup.Name} is Already exist."));
        }
Ejemplo n.º 11
0
        public void ApoGroupShouldReturnCorrectCriteriaWhenGivenDivision()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var parameter = new ApoGroupResourceParameter(1, 10, 1, "");

            var sut = service.GetAll(parameter);

            Assert.Equal(sut.CurrentPage, 1);
            Assert.Equal(sut.HasNext, (_apoGroup.Count(x => x.DivisionId == parameter.ApoDivsionId) / 10) > 1);
            Assert.Equal(sut.HasPrevious, false);
            Assert.True(sut.List.Count() <= 10);
            Assert.IsType <PagedList <IApoGroupDataTranferObject> >(sut);
            Assert.True(sut.List.All(x => x.DivisionId == parameter.ApoDivsionId));
            Assert.True(sut.List.All(x => x.DivisionName.Equals(_apoDivision.SingleOrDefault(a => a.Id == x.DivisionId)?.Name)));
        }
Ejemplo n.º 12
0
        public void ApoGroupShouldReturnCorrectValueWhenGetAll()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var parameter = new ApoGroupResourceParameter(1, 10, null, "");

            var sut = service.GetAll(parameter);


            Assert.Equal(sut.CurrentPage, 1);
            Assert.Equal(sut.HasNext, true);
            Assert.Equal(sut.HasPrevious, false);
            Assert.True(sut.List.Count() <= 10);
            Assert.IsType <PagedList <IApoGroupDataTranferObject> >(sut);
            Assert.True(sut.List.All(x => x.DivisionName.Equals(_apoDivision.Single(a => a.Id == x.DivisionId).Name)));
        }
Ejemplo n.º 13
0
        public void ApoGroupShouldReturnCorrectvaluewhenSearchByName()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var searchObj = new ApoGroupForCreateOrUpdate()
            {
                Name = "Packaged"
            };

            var sut = service.GetByName(searchObj);

            var compareObj = Mapper.Map <ApoGroupDto>(_apoGroup.Single(x => x.Name.Equals(searchObj.Name)));

            compareObj.DivisionName = _apoDivision.Single(x => x.Id == compareObj.DivisionId).Name;

            AssertObjects.PropertyValuesAreEquals(sut, Mapper.Map <ApoGroupDto>(compareObj));
        }
Ejemplo n.º 14
0
        public void ApoGroupServiceShouldReturnCorrectValueWhenUpdateSameValueToSameId()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var editApo = new ApoGroupForCreateOrUpdate()
            {
                Name = "Packaged",
            };

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

            var compareObj = Mapper.Map <ApoGroupDto>(_apoGroup.Single(x => x.Id == 1));

            compareObj.DivisionName = _apoDivision.Single(x => x.Id == compareObj.DivisionId).Name;

            Assert.Equal(sut.Id, 1);
            AssertObjects.PropertyValuesAreEquals(sut, compareObj);
        }
Ejemplo n.º 15
0
        public void ApoGroupSouldReturnCreatedApoWhenCreateSuccess()
        {
            var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository);

            var createdApoGroup = new ApoGroupForCreateOrUpdate()
            {
                Name = "New Group",
            };

            var nextCode           = (Convert.ToInt32(_apoGroup.Last().Code) + 1).ToString("D2");
            var compareEqualObject = Mapper.Map <ApoGroupDto>(createdApoGroup);

            compareEqualObject.Code         = nextCode;
            compareEqualObject.Id           = _apoGroup.Last().Id + 1;
            compareEqualObject.DivisionName = _apoDivision.Single(x => x.Id == compareEqualObject.DivisionId).Name;

            var sut = service.Create(createdApoGroup);

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