public void Create(CreateFamilyDto inputFamily) { var family = MapToEntity(inputFamily); if (_familyManager.ParentsFamilyExists(family)) { throw new UserFriendlyException(L("FamilyAlreadyExists")); } GetAndAssignFamilyParents(family); _familyRepository.Insert(family); }
public void Should_Throw_UserFriendlyException_If_Single_Father_Family_Already_Exists() { var singleManId = GetUnmarriedMan().Id; UsingDbContext(Context => { Context.Families.Add(new Family { FatherId = singleManId }); }); var familyInputWithOnlyFather = new CreateFamilyDto { FatherId = singleManId }; Should.Throw <UserFriendlyException>(() => { _familyAppService.Create(familyInputWithOnlyFather); }) .Message.ShouldBe("This family already exists"); }
public void Should_Throw_UserFriendlyException_If_Family_Already_Exists() { var singleManId = GetUnmarriedMan().Id; var singleWomenId = GetUnmarriedWomen().Id; //Add family too make it exists UsingDbContext(Context => { Context.Families.Add(new Family { FatherId = singleManId, MotherId = singleWomenId }); }); var familyInputWithBothParents = new CreateFamilyDto { FatherId = singleManId, MotherId = singleWomenId }; Should.Throw <UserFriendlyException>(() => { _familyAppService.Create(familyInputWithBothParents); }) .Message.ShouldBe("This family already exists"); }
protected Family MapToEntity(CreateFamilyDto input) { return(_objectMapper.Map <Family>(input)); }