Ejemplo n.º 1
0
        public void Can_EfCore_Initialize_The_Strings_IEnumerable_Properly()
        {
            var provider = new InMemorySqliteProvider();
            var strings  = new Strings(1);

            strings.AddString("1");
            strings.AddString("2");

            strings.AddString("1");
            strings.AddString("2");

            Assert.Equal(2, strings.Stringies.Count());

            try
            {
                using (var ctx = new HashsetContext(provider.DbOptions))
                {
                    ctx.Add(strings);
                    ctx.SaveChanges();
                }
                using (var ctx = new HashsetContext(provider.DbOptions))
                {
                    //throws: System.InvalidCastException :
                    //Unable to cast object of type 'System.Collections.Generic.List`1[System.String]' to type 'System.Collections.Generic.HashSet`1[System.String]'.
                    var efStrings = ctx.Strings.First();
                }
            }
            finally
            {
                provider.DestroyDb();
            }
        }
Ejemplo n.º 2
0
        public void Ensure_Duplicate_Free_Features_After_Manual_HashSet_Instantiation()
        {
            var provider = new InMemorySqliteProvider();

            var vehicleInitialized = new VehicleInitialized("vehicle1");

            vehicleInitialized.AddFeature(new Feature(1));
            vehicleInitialized.AddFeature(new Feature(2));

            vehicleInitialized.AddFeature(new Feature(1));
            vehicleInitialized.AddFeature(new Feature(2));

            Assert.Equal(2, vehicleInitialized.Features.Count());

            try
            {
                using (var ctx = new HashsetContext(provider.DbOptions))
                {
                    ctx.Add(vehicleInitialized);
                    ctx.SaveChanges();
                }
                using (var ctx = new HashsetContext(provider.DbOptions))
                {
                    var efVehicle = ctx.VehiclesWithHashSetInitialized.Include(e => e.Features).First();

                    Assert.True(efVehicle.Features.Count() == 2);

                    efVehicle.AddFeature(new Feature(1));
                    efVehicle.AddFeature(new Feature(2));

                    //succeeds:
                    Assert.Equal(2, efVehicle.Features.Count());
                }
            }
            finally
            {
                provider.DestroyDb();
            }
        }
Ejemplo n.º 3
0
        public void Ensure_Duplicate_Free_Features_When_Features_Collection_Instantiation_leftTo_EfCore()
        {
            var provider = new InMemorySqliteProvider();

            var vehicle = new Vehicle("vehicle1");

            vehicle.AddFeature(new Feature(1));
            vehicle.AddFeature(new Feature(2));

            vehicle.AddFeature(new Feature(1));
            vehicle.AddFeature(new Feature(2));

            Assert.Equal(2, vehicle.Features.Count());

            try
            {
                using (var ctx = new HashsetContext(provider.DbOptions))
                {
                    ctx.Add(vehicle);
                    ctx.SaveChanges();
                }
                using (var ctx = new HashsetContext(provider.DbOptions))
                {
                    var efVehicle = ctx.Vehicles.Include(e => e.Features).First();

                    Assert.True(efVehicle.Features.Count() == 2);

                    efVehicle.AddFeature(new Feature(1));
                    efVehicle.AddFeature(new Feature(2));

                    //fails:
                    Assert.Equal(2, efVehicle.Features.Count());
                }
            }
            finally
            {
                provider.DestroyDb();
            }
        }