Exemplo n.º 1
0
 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 { }
 }
Exemplo n.º 2
0
        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();
            }
        }