private static DemoEntityNotFoundException GetDemoEntityNotFoundException(Guid primaryObjectId) { var ex = new DemoEntityNotFoundException(); ex.Data.Add($"{nameof(DomainModels.PrimaryObject)}.{nameof(DomainModels.PrimaryObject.Id)}", primaryObjectId.ToString()); return(ex); }
public async Task <DomainModels.SecondaryObject> CreateAsync(Guid primaryObjectId, ApiModels.SecondaryObject inputModel) { Ensure.That(primaryObjectId, nameof(primaryObjectId)).IsNotEmpty(); Ensure.That(inputModel, nameof(inputModel)).IsNotNull(); var domainPrimaryObject = await _primaryObjectRepoistory.GetByIdAsync(primaryObjectId); Ensure.That(domainPrimaryObject, nameof(domainPrimaryObject)) .WithException(_ => { var ex = new DemoEntityNotFoundException(); ex.Data.Add($"{nameof(DomainModels.PrimaryObject)}.{nameof(DomainModels.PrimaryObject.Id)}", primaryObjectId.ToString()); return(ex); }) .IsNotNull(); var domainSecondaryObject = new DomainModels.SecondaryObject(Guid.NewGuid()); Map(inputModel, domainSecondaryObject); domainSecondaryObject.PrimaryObject = domainPrimaryObject; domainSecondaryObject.PrimaryObject_Id = domainPrimaryObject.Id; domainPrimaryObject.SecondaryObjects.Add(domainSecondaryObject); await _unitOfWork.SaveChangesAsync(); return(domainSecondaryObject); }
public void DemoEntityNotFoundException_Constructor_MessageArgument_Null() { // This test verifies that the default constructor works. // Note: this test is useless except for code coverage since we are testing the constructor with no custom logic. var ex = new DemoEntityNotFoundException(null); Assert.AreEqual("Exception of type 'Rightpoint.UnitTesting.Demo.Common.Exceptions.DemoEntityNotFoundException' was thrown.", ex.Message); Assert.IsNull(ex.InnerException); }
public void DemoEntityNotFoundException_Constructor_MessageArgument_Valid() { // This test verifies that the default constructor works. // Note: this test is useless except for code coverage since we are testing the constructor with no custom logic. var ex = new DemoEntityNotFoundException("test"); Assert.AreEqual("test", ex.Message); Assert.IsNull(ex.InnerException); }
public void DemoEntityNotFoundException_Constructor_Serialization() { // This test verifies that the default constructor works. // Note: this test is useless except for code coverage since we are testing default serialization. DemoException inputException = new DemoEntityNotFoundException("test", new Exception("Inner")); byte[] bytes = BinarySerializer.Serialize(inputException); Assert.IsNotNull(bytes); DemoEntityNotFoundException deserializedException = BinarySerializer.Deserialize <DemoEntityNotFoundException>(bytes); Assert.IsNotNull(deserializedException); Assert.AreEqual(inputException.Message, deserializedException.Message); Assert.IsNotNull(deserializedException.InnerException); Assert.AreEqual(typeof(Exception), deserializedException.InnerException.GetType()); Assert.AreEqual(inputException.InnerException.Message, deserializedException.InnerException.Message); Assert.IsNull(deserializedException.InnerException.InnerException); }