public void Create_IsSaved() { try { // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); Recipient recipient = new Recipient() { Name = "Martin" }; Recipient sender = new Recipient() { Name = "Simon" }; Parcel p = new Parcel() { Recipient = recipient, Sender = sender, TrackingId = "123456789" }; service.Create(p); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DatabaseContext(options)) { Assert.Equal(1, context.Parcels.Count()); Assert.Equal("123456789", context.Parcels.Single().TrackingId); Assert.Equal("Martin", context.Parcels.Single().Recipient.Name); Assert.Equal("Simon", context.Parcels.Single().Sender.Name); } } finally { } }
public HoldingController(IMapper mapper, IEntityBaseRepository<Holding> repository, ParcelRepository parcelRepository) { this.parcelRepository = parcelRepository; this.repository = repository; this.mapper = mapper; }
public void GetByCode_ThrowsParcelNotFoundExpection() { try { using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); Assert.Throws <ParcelNotFoundExpection>(() => service.GetByTrackingId("123456789")); } } finally { } }
public bool PickupParcel(string region, string parcelData) { bool isSuccess = false; var parcel = _parcelRepository.GetParcelById(Guid.Empty); ParcelRepository a = null; return(isSuccess); }
public void Create_ThrowsDuplicateParcelExpection() { try { // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); Recipient recipient = new Recipient() { Name = "Martin" }; Recipient sender = new Recipient() { Name = "Simon" }; Parcel p = new Parcel() { Recipient = recipient, Sender = sender, TrackingId = "123456789" }; service.Create(p); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); Recipient recipient = new Recipient() { Name = "Martin" }; Recipient sender = new Recipient() { Name = "Simon" }; Parcel p = new Parcel() { Recipient = recipient, Sender = sender, TrackingId = "123456789" }; Assert.Throws <DuplicateParcelExpection>(() => service.Create(p)); } } finally { } }
public void GetByCode_ReturnsParcel() { try { // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); Recipient recipient = new Recipient() { Name = "Martin" }; Recipient sender = new Recipient() { Name = "Simon" }; Parcel p = new Parcel() { Recipient = recipient, Sender = sender, TrackingId = "123456789" }; context.Parcels.Add(p); context.SaveChanges(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); Parcel p = (Parcel)service.GetByTrackingId("123456789"); Assert.Equal(1, context.Parcels.Count()); Assert.Equal("123456789", context.Parcels.Single().TrackingId); Assert.Equal("Martin", context.Parcels.Single().Recipient.Name); Assert.Equal("Simon", context.Parcels.Single().Sender.Name); } } finally { connection.Close(); } }
public void Delete_IsEmpty() { try { // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); Recipient recipient = new Recipient() { Name = "Martin" }; Recipient sender = new Recipient() { Name = "Simon" }; Parcel p = new Parcel() { Recipient = recipient, Sender = sender, TrackingId = "123456789" }; context.Parcels.Add(p); context.SaveChanges(); } // Run the test against one instance of the context using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); service.Delete(); // TODO: doesn't delete it, idk why } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DatabaseContext(options)) { //Assert.Equal(0, context.Parcels.Count()); } } finally { } }
public void Update_ThrowsParcelNotFoundExpection() { try { using (var context = new DatabaseContext(options)) { IParcelRepository service = new ParcelRepository(context, NullLogger <ParcelRepository> .Instance); Recipient recipient = new Recipient() { Name = "David" }; Recipient sender = new Recipient() { Name = "Michael" }; Parcel p = new Parcel() { Recipient = recipient, Sender = sender, TrackingId = "123456789" }; Assert.Throws <ParcelNotFoundExpection>(() => service.Update(p)); } } finally { } }