Example #1
0
        public async virtual Task <ColumnSameAsFKTable> Create(ColumnSameAsFKTable item)
        {
            this.Context.Set <ColumnSameAsFKTable>().Add(item);
            await this.Context.SaveChangesAsync();

            this.Context.Entry(item).State = EntityState.Detached;
            return(item);
        }
Example #2
0
        public virtual async Task Migrate()
        {
            var columnSameAsFKTableItem1 = new ColumnSameAsFKTable();

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

            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, 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, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("01:00:00"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A");
            this.Context.TestAllFieldTypes.Add(testAllFieldTypeItem1);

            var testAllFieldTypesNullableItem1 = new TestAllFieldTypesNullable();

            testAllFieldTypesNullableItem1.SetProperties(1, 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, 1, BitConverter.GetBytes(1), 1m, "A", "A", 1m, "A", 1m, DateTime.Parse("1/1/1987 12:00:00 AM"), 1, 1m, "A", TimeSpan.Parse("01:00:00"), BitConverter.GetBytes(1), 1, Guid.Parse("8420cdcf-d595-ef65-66e7-dff9f98764da"), BitConverter.GetBytes(1), "A", "A");
            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();
        }
        public async void Create()
        {
            Mock <ILogger <ColumnSameAsFKTableRepository> > loggerMoc = ColumnSameAsFKTableRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ColumnSameAsFKTableRepositoryMoc.GetContext();
            var repository = new ColumnSameAsFKTableRepository(loggerMoc.Object, context);

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

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

            record.Should().NotBeNull();
        }
        public async void Create()
        {
            Mock <ILogger <ColumnSameAsFKTableRepository> > loggerMoc = ColumnSameAsFKTableRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ColumnSameAsFKTableRepositoryMoc.GetContext();
            var repository = new ColumnSameAsFKTableRepository(loggerMoc.Object, context);

            var entity = new ColumnSameAsFKTable();

            entity.SetProperties(default(int), 1, 1);
            await repository.Create(entity);

            var records = await context.Set <ColumnSameAsFKTable>().ToListAsync();

            records.Count.Should().Be(2);
        }
Example #5
0
        public async virtual Task Delete(
            int id)
        {
            ColumnSameAsFKTable record = await this.GetById(id);

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

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

            await this.Context.SaveChangesAsync();
        }
        public async void Get()
        {
            Mock <ILogger <ColumnSameAsFKTableRepository> > loggerMoc = ColumnSameAsFKTableRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ColumnSameAsFKTableRepositoryMoc.GetContext();
            var repository = new ColumnSameAsFKTableRepository(loggerMoc.Object, context);

            ColumnSameAsFKTable entity = new ColumnSameAsFKTable();

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

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

            record.Should().NotBeNull();
        }
        public async void Delete()
        {
            Mock <ILogger <ColumnSameAsFKTableRepository> > loggerMoc = ColumnSameAsFKTableRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ColumnSameAsFKTableRepositoryMoc.GetContext();
            var repository             = new ColumnSameAsFKTableRepository(loggerMoc.Object, context);
            ColumnSameAsFKTable entity = new ColumnSameAsFKTable();

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

            await repository.Delete(entity.Id);

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

            modifiedRecord.Should().BeNull();
        }
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <ColumnSameAsFKTableRepository> > loggerMoc = ColumnSameAsFKTableRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ColumnSameAsFKTableRepositoryMoc.GetContext();
            var repository             = new ColumnSameAsFKTableRepository(loggerMoc.Object, context);
            ColumnSameAsFKTable entity = new ColumnSameAsFKTable();

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

            await repository.Update(new ColumnSameAsFKTable());

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

            modifiedRecord.Should().NotBeNull();
        }
        public async void Update_Entity_Is_Not_Tracked()
        {
            Mock <ILogger <ColumnSameAsFKTableRepository> > loggerMoc = ColumnSameAsFKTableRepositoryMoc.GetLoggerMoc();
            ApplicationDbContext context = ColumnSameAsFKTableRepositoryMoc.GetContext();
            var repository             = new ColumnSameAsFKTableRepository(loggerMoc.Object, context);
            ColumnSameAsFKTable entity = new ColumnSameAsFKTable();

            entity.SetProperties(default(int), 1, 1);
            context.Set <ColumnSameAsFKTable>().Add(entity);
            await context.SaveChangesAsync();

            context.Entry(entity).State = EntityState.Detached;

            await repository.Update(entity);

            var records = await context.Set <ColumnSameAsFKTable>().ToListAsync();

            records.Count.Should().Be(2);
        }