예제 #1
0
 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 { }
 }
예제 #2
0
        public void Update_IsUpdated()
        {
            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))
                {
                    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);
                }

                // 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 = "David"
                    };
                    Recipient sender = new Recipient()
                    {
                        Name = "Michael"
                    };
                    Parcel p = new Parcel()
                    {
                        Recipient = recipient, Sender = sender, TrackingId = "123456789"
                    };
                    service.Update(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("David", context.Parcels.Single().Recipient.Name);
                    Assert.Equal("Michael", context.Parcels.Single().Sender.Name);
                }
            }
            finally { }
        }