Esempio n. 1
0
        public async Task TestDeleteAsync()
        {
            var institute = createInstitutionInstance();

            using (var factory = new TemakiInMemoryContextFactory())
            {
                var id = await SaveInstitute(factory, institute);


                using (var context = factory.CreateContext())
                {
                    var repository = new InstitutionRepository(context);



                    await repository.DeleteAsync(id);
                }

                var institutionGotten = await GetInstitution(factory, id);

                Assert.True(
                    institutionGotten is null
                    );
            }
        }
Esempio n. 2
0
        public async Task TestUpdateAsync()
        {
            var institute = createInstitutionInstance();

            using (var factory = new TemakiInMemoryContextFactory())
            {
                var id = await SaveInstitute(factory, institute);

                var institution2 = new Institution()
                {
                    Id      = id,
                    Name    = "minha casa",
                    Address = "nossa casa"
                };
                using (var context = factory.CreateContext())
                {
                    var repository = new InstitutionRepository(context);



                    await repository.UpdateAsync(institution2);
                }

                var institutionGotten = await GetInstitution(factory, id);

                Assert.True(
                    compareInstitutes(institution2, institutionGotten)
                    );
            }
        }
Esempio n. 3
0
 private static async Task <Institution> GetInstitution(TemakiInMemoryContextFactory fac, Guid id)
 {
     using (var context = fac.CreateContext())
     {
         return(await context.FindAsync <Institution>(id));
     }
 }
Esempio n. 4
0
        private static async Task <Guid> SaveInstitute(TemakiInMemoryContextFactory ctxf, Institution i)
        {
            using (var ctx = ctxf.CreateContext())
            {
                await ctx.AddAsync <Institution>(i);

                await ctx.SaveChangesAsync();

                return(i.Id);
            }
        }
Esempio n. 5
0
        public async Task TestAddAsync()
        {
            var institute = createInstitutionInstance();

            using (var factory = new TemakiInMemoryContextFactory())
            {
                using (var context = factory.CreateContext())
                {
                    var instituteRepository = new InstitutionRepository(context);
                    await instituteRepository.AddAsync(institute);

                    await context.SaveChangesAsync();
                }

                using (var context = factory.CreateContext())
                {
                    var success = await context.Institutions.AnyAsync(
                        i1 => (i1.Address == institute.Address) && (i1.Name == institute.Name)
                        );

                    Assert.True(success);
                }
            }
        }
Esempio n. 6
0
        public async Task TestGetAsync()
        {
            var institute = createInstitutionInstance();

            using (var factory = new TemakiInMemoryContextFactory())
            {
                var id = await SaveInstitute(factory, institute);


                using (var context = factory.CreateContext())
                {
                    var repository      = new InstitutionRepository(context);
                    var institionGotten = await repository.GetAsync(id);


                    Assert.True(
                        compareInstitutes(institute, institionGotten)
                        );
                }
            }
        }