Exemple #1
0
        public void InserirNovasMaterias()
        {
            //arrange
            var options = new DbContextOptionsBuilder <CaseSchoolContext>()
                          .UseInMemoryDatabase("DbSchool")
                          .Options;
            var                       context     = new CaseSchoolContext(options);
            IUnitOfWork               uow         = new UnitOfWork(context);
            IRepository <Subject>     subjectRepo = uow.Repository <Subject>();
            IRepository <WeightProof> weightRepo  = uow.Repository <WeightProof>();

            IFirstHandler handler = new Mock <FirstHandler>(context).Object;

            var controlador = new ApiController(context);
            var names       = new List <String>()
            {
                "Portugues", "Ingles", "Historia"
            };
            var pesos = new List <double>()
            {
                2.0, 1.4, 1.6, 1.5, 1.5, 3.0, 5.0, 1.0, 4.0
            };

            controlador.InsertSubjects(names, pesos);
            //act
            var response = subjectRepo.Queryable().Where(t => t.Name == "Portugues").FirstOrDefault();
            ICollection <WeightProof> response2 = (ICollection <WeightProof>)weightRepo.FindAll().Result;

            //assert
            Assert.NotNull(response);
            Assert.Equal(9, response2.Count());
        }
        public void MontagemDeBancoDeDadosUsandoTodasEntidades()
        {
            //arrage
            var options = new DbContextOptionsBuilder <CaseSchoolContext>()
                          .UseInMemoryDatabase("DbSchool")
                          .Options;
            var context = new CaseSchoolContext(options, new Mock <IConfiguration>().Object);

            var estudante      = new Student(Guid.NewGuid().ToString(), false);
            var listaEstudante = new List <Student>()
            {
                estudante
            };
            var turma = new Class(Guid.NewGuid().ToString(), listaEstudante);
            var pesos = new List <WeightProof>()
            {
                new WeightProof(Guid.NewGuid().ToString(), new decimal(1.2)), new WeightProof(Guid.NewGuid().ToString(), new decimal(1.8)), new WeightProof(Guid.NewGuid().ToString(), new decimal(2.0))
            };
            var materia = new Subject(Guid.NewGuid().ToString(), "Portugues", pesos);

            context.Student.Add(estudante);
            context.Class.Add(turma);
            foreach (var peso in pesos)
            {
                context.WeightProof.Add(peso);
            }
            context.Subject.Add(materia);

            //act
            var response = context.SaveChanges();

            //assert
            Assert.Equal(6, response);
        }
        public void ConsultaDeBancoDeDadosUtilizandoJoin()
        {
            //arrage
            var options = new DbContextOptionsBuilder <CaseSchoolContext>()
                          .UseInMemoryDatabase("DbSchool")
                          .Options;
            var context = new CaseSchoolContext(options, new Mock <IConfiguration>().Object);

            var estudantes = new List <Student>()
            {
                new Student(Guid.NewGuid().ToString(), false), new Student(Guid.NewGuid().ToString(), true)
            };
            var listaEstudante = new List <Student>(estudantes);
            var turma          = new Class(Guid.NewGuid().ToString(), listaEstudante);
            var pesos          = new List <WeightProof>()
            {
                new WeightProof(Guid.NewGuid().ToString(), new decimal(1.2)), new WeightProof(Guid.NewGuid().ToString(), new decimal(1.8)), new WeightProof(Guid.NewGuid().ToString(), new decimal(2.0))
            };
            var materia = new Subject(Guid.NewGuid().ToString(), "Portugues", pesos);
            var notas   = new List <StudentGrade>()
            {
                new StudentGrade(Guid.NewGuid().ToString(), new decimal(8.5), estudantes[0], materia), new StudentGrade(Guid.NewGuid().ToString(), new decimal(6), estudantes[1], materia)
            };


            foreach (var estudante in estudantes)
            {
                context.Student.Add(estudante);
            }
            context.Class.Add(turma);
            foreach (var peso in pesos)
            {
                context.WeightProof.Add(peso);
            }
            foreach (var nota in notas)
            {
                context.StudentGrade.Add(nota);
            }

            context.Subject.Add(materia);
            context.SaveChanges();

            var contextStudent      = context.Student;
            var contextStudentGrade = context.StudentGrade;

            //act
            var select = from s in context.Student join g in context.StudentGrade on s equals g.Student select new { s.Registration, s.Accredited, g.Average };

            //assert
            Console.WriteLine(select);
            Assert.Equal(2, select.Count());
        }
        public void FuncionamentoDeRepositorio()
        {
            //arrange
            var options = new DbContextOptionsBuilder <CaseSchoolContext>()
                          .UseInMemoryDatabase("DbSchool")
                          .Options;
            var                   context = new CaseSchoolContext(options, new Mock <IConfiguration>().Object);
            IUnitOfWork           uow     = new UnitOfWork(context);
            IRepository <Subject> repo    = uow.Repository <Subject>();

            repo.Insert(new Subject(Guid.NewGuid().ToString(), "teste", new List <WeightProof>()));
            //act
            var response = uow.Commit().IsCompletedSuccessfully;

            //asert
            Assert.Equal("True", response.ToString());
        }
        public void QueryPersonalizada()
        {
            //arrange
            var options = new DbContextOptionsBuilder <CaseSchoolContext>()
                          .UseInMemoryDatabase("DbSchool")
                          .Options;
            var                   context = new CaseSchoolContext(options, new Mock <IConfiguration>().Object);
            IUnitOfWork           uow     = new UnitOfWork(context);
            IRepository <Subject> repo    = uow.Repository <Subject>();

            repo.Insert(new Subject(Guid.NewGuid().ToString(), "teste", new List <WeightProof>()));
            uow.Commit();
            //act
            var items = repo.Queryable().ToList();

            //asert
            Assert.Equal(1, items.Count);
        }
Exemple #6
0
        public void InserirNovasTurmasAlunos()
        {
            //arrange
            var options = new DbContextOptionsBuilder <CaseSchoolContext>()
                          .UseInMemoryDatabase("DbSchool")
                          .Options;
            var                   context     = new CaseSchoolContext(options);
            IUnitOfWork           uow         = new UnitOfWork(context);
            IRepository <Class>   classRepo   = uow.Repository <Class>();
            IRepository <Student> studentRepo = uow.Repository <Student>();

            var controlador = new ApiController(context);

            controlador.InsertClassAndStudent(2, 2);
            //act
            ICollection <Class>   response  = (ICollection <Class>)classRepo.FindAll().Result;
            ICollection <Student> response2 = (ICollection <Student>)studentRepo.FindAll().Result;

            //assert
            Assert.Equal(2.ToString(), response.Count().ToString());
            Assert.Equal(4.ToString(), response2.Count().ToString());
        }
Exemple #7
0
        //private readonly CaseSchoolContext dbContext;

        public ApiController(CaseSchoolContext dbContext)
        {
            this._handler = new FirstHandler(dbContext);
        }
Exemple #8
0
 public UnitOfWork(CaseSchoolContext dbContext)
 {
     this._dbContext = dbContext;
 }
Exemple #9
0
 public FirstHandler(CaseSchoolContext dbContext)
 {
     this._uow = new UnitOfWork(dbContext);
 }
 public Repository(IUnitOfWork unitOfWork)
 {
     this._unitOfWork = unitOfWork;
     this._dbContext  = unitOfWork.Context;
     this._dbSet      = unitOfWork.Context.Set <TEntity>();
 }