Example #1
0
        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 { }
        }
Example #2
0
        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 { }
        }