public void ApoGroupShouldReturnTrueWhenDelteSuccess() { var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository); var sut = service.Delete(0); Assert.True(sut); }
public void ApoGroupShouldReturnFalseWhenDeleteFailed() { var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository); var sut = service.Delete(150); Assert.False(sut); }
public void ApoGroupShouldReturnNullWhenIdIsNotExistInDatabase() { var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository); var sut = service.GetById(100); Assert.Null(sut); }
public void ApoGroupServiceShouldReturnAllItem() { var service = new ApoGroupService(_apoGroupRepository, _apoDivisionRepository); var sut = service.GetAll(); Assert.IsType <List <ApoGroupDto> >(sut); Assert.Equal(sut.Count(), _apoGroup.Count()); }
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()); }
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()))); }
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); }
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); }
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.")); }
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.")); }
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))); }
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))); }
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)); }
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); }
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); }