public async virtual Task <SchemaBPerson> Create(SchemaBPerson item)
        {
            this.Context.Set <SchemaBPerson>().Add(item);
            await this.Context.SaveChangesAsync();

            this.Context.Entry(item).State = EntityState.Detached;
            return(item);
        }
Ejemplo n.º 2
0
        public void Migrate()
        {
            var personItem1 = new Person();

            personItem1.SetProperties(1, "A");
            this.context.People.Add(personItem1);

            var rowVersionCheckItem1 = new RowVersionCheck();

            rowVersionCheckItem1.SetProperties(1, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            this.context.RowVersionChecks.Add(rowVersionCheckItem1);

            var selfReferenceItem1 = new SelfReference();

            selfReferenceItem1.SetProperties(1, 1, 1);
            this.context.SelfReferences.Add(selfReferenceItem1);

            var tableItem1 = new Table();

            tableItem1.SetProperties(1, "A");
            this.context.Tables.Add(tableItem1);

            var testAllFieldTypeItem1 = new TestAllFieldType();

            testAllFieldTypeItem1.SetProperties(1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1m, 1m, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("0"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A", 1);
            this.context.TestAllFieldTypes.Add(testAllFieldTypeItem1);

            var testAllFieldTypesNullableItem1 = new TestAllFieldTypesNullable();

            testAllFieldTypesNullableItem1.SetProperties(1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1m, 1m, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("0"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A", 1);
            this.context.TestAllFieldTypesNullables.Add(testAllFieldTypesNullableItem1);

            var timestampCheckItem1 = new TimestampCheck();

            timestampCheckItem1.SetProperties(1, "A", BitConverter.GetBytes(1));
            this.context.TimestampChecks.Add(timestampCheckItem1);

            this.context.SaveChanges();
            var schemaAPersonItem1 = new SchemaAPerson();

            schemaAPersonItem1.SetProperties(1, "A");
            this.context.SchemaAPersons.Add(schemaAPersonItem1);

            this.context.SaveChanges();
            var schemaBPersonItem1 = new SchemaBPerson();

            schemaBPersonItem1.SetProperties(1, "A");
            this.context.SchemaBPersons.Add(schemaBPersonItem1);

            var personRefItem1 = new PersonRef();

            personRefItem1.SetProperties(1, 1, 1);
            this.context.PersonRefs.Add(personRefItem1);

            this.context.SaveChanges();
        }
Ejemplo n.º 3
0
        public async void Create()
        {
            Mock <ILogger <SchemaBPersonRepository> > loggerMoc = SchemaBPersonRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = SchemaBPersonRepositoryMoc.GetContext();
            var repository = new SchemaBPersonRepository(loggerMoc.Object, context);

            var entity = new SchemaBPerson();
            await repository.Create(entity);

            var record = await context.Set <SchemaBPerson>().FirstOrDefaultAsync();

            record.Should().NotBeNull();
        }
        public async virtual Task Delete(
            int id)
        {
            SchemaBPerson record = await this.GetById(id);

            if (record == null)
            {
                return;
            }
            else
            {
                this.Context.Set <SchemaBPerson>().Remove(record);
                await this.Context.SaveChangesAsync();
            }
        }
        public async virtual Task Update(SchemaBPerson item)
        {
            var entity = this.Context.Set <SchemaBPerson>().Local.FirstOrDefault(x => x.Id == item.Id);

            if (entity == null)
            {
                this.Context.Set <SchemaBPerson>().Attach(item);
            }
            else
            {
                this.Context.Entry(entity).CurrentValues.SetValues(item);
            }

            await this.Context.SaveChangesAsync();
        }
Ejemplo n.º 6
0
        public async void Get()
        {
            Mock <ILogger <SchemaBPersonRepository> > loggerMoc = SchemaBPersonRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = SchemaBPersonRepositoryMoc.GetContext();
            var repository = new SchemaBPersonRepository(loggerMoc.Object, context);

            SchemaBPerson entity = new SchemaBPerson();

            context.Set <SchemaBPerson>().Add(entity);
            await context.SaveChangesAsync();

            var record = await repository.Get(entity.Id);

            record.Should().NotBeNull();
        }
Ejemplo n.º 7
0
        public async void Delete()
        {
            Mock <ILogger <SchemaBPersonRepository> > loggerMoc = SchemaBPersonRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = SchemaBPersonRepositoryMoc.GetContext();
            var           repository     = new SchemaBPersonRepository(loggerMoc.Object, context);
            SchemaBPerson entity         = new SchemaBPerson();

            context.Set <SchemaBPerson>().Add(entity);
            await context.SaveChangesAsync();

            await repository.Delete(entity.Id);

            SchemaBPerson modifiedRecord = await context.Set <SchemaBPerson>().FirstOrDefaultAsync();

            modifiedRecord.Should().BeNull();
        }
Ejemplo n.º 8
0
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <SchemaBPersonRepository> > loggerMoc = SchemaBPersonRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = SchemaBPersonRepositoryMoc.GetContext();
            var           repository     = new SchemaBPersonRepository(loggerMoc.Object, context);
            SchemaBPerson entity         = new SchemaBPerson();

            context.Set <SchemaBPerson>().Add(entity);
            await context.SaveChangesAsync();

            await repository.Update(new SchemaBPerson());

            var modifiedRecord = context.Set <SchemaBPerson>().FirstOrDefaultAsync();

            modifiedRecord.Should().NotBeNull();
        }
Ejemplo n.º 9
0
        public async void Migrate()
        {
            var columnSameAsFKTableItem1 = new ColumnSameAsFKTable();

            columnSameAsFKTableItem1.SetProperties(1, 1, 1);
            this.context.ColumnSameAsFKTables.Add(columnSameAsFKTableItem1);

            var compositePrimaryKeyItem1 = new CompositePrimaryKey();

            compositePrimaryKeyItem1.SetProperties(1, 1);
            this.context.CompositePrimaryKeys.Add(compositePrimaryKeyItem1);

            var includedColumnTestItem1 = new IncludedColumnTest();

            includedColumnTestItem1.SetProperties(1, "A", "A");
            this.context.IncludedColumnTests.Add(includedColumnTestItem1);

            var personItem1 = new Person();

            personItem1.SetProperties(1, "A");
            this.context.People.Add(personItem1);

            var rowVersionCheckItem1 = new RowVersionCheck();

            rowVersionCheckItem1.SetProperties(1, "A", Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"));
            this.context.RowVersionChecks.Add(rowVersionCheckItem1);

            var selfReferenceItem1 = new SelfReference();

            selfReferenceItem1.SetProperties(1, 1, 1);
            this.context.SelfReferences.Add(selfReferenceItem1);

            var tableItem1 = new Table();

            tableItem1.SetProperties(1, "A");
            this.context.Tables.Add(tableItem1);

            var testAllFieldTypeItem1 = new TestAllFieldType();

            testAllFieldTypeItem1.SetProperties(1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("0"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A", 1);
            this.context.TestAllFieldTypes.Add(testAllFieldTypeItem1);

            var testAllFieldTypesNullableItem1 = new TestAllFieldTypesNullable();

            testAllFieldTypesNullableItem1.SetProperties(1, BitConverter.GetBytes(1), true, "A", DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTime.Parse("1/1/1987 12:00:00 AM"), DateTimeOffset.Parse("1/1/1987 12:00:00 AM"), 1, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("0"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A", 1);
            this.context.TestAllFieldTypesNullables.Add(testAllFieldTypesNullableItem1);

            var timestampCheckItem1 = new TimestampCheck();

            timestampCheckItem1.SetProperties(1, "A", BitConverter.GetBytes(1));
            this.context.TimestampChecks.Add(timestampCheckItem1);

            var vPersonItem1 = new VPerson();

            vPersonItem1.SetProperties(1, "A");
            this.context.VPersons.Add(vPersonItem1);

            await this.context.SaveChangesAsync();

            var schemaAPersonItem1 = new SchemaAPerson();

            schemaAPersonItem1.SetProperties(1, "A");
            this.context.SchemaAPersons.Add(schemaAPersonItem1);

            await this.context.SaveChangesAsync();

            var schemaBPersonItem1 = new SchemaBPerson();

            schemaBPersonItem1.SetProperties(1, "A");
            this.context.SchemaBPersons.Add(schemaBPersonItem1);

            var personRefItem1 = new PersonRef();

            personRefItem1.SetProperties(1, 1, 1);
            this.context.PersonRefs.Add(personRefItem1);

            await this.context.SaveChangesAsync();
        }