Exemplo n.º 1
0
 public void SetUp()
 {
     using (var context = new ManagementContext())
     {
         context.Database.Initialize(true);
     }
 }
Exemplo n.º 2
0
        public void DbEntityEntry_State_Modified_Only_Set_Current_Entity()
        {
            //Assert
            var customer = GetFirstDisconnectedCustomerFullyLoaded();

            customer.Name = "Cliente modificado";

            var          address   = customer.Addresses.First();
            const string newRegion = "Región modificada";

            address.Region = newRegion;

            using (var context = new ManagementContext())
            {
                //Act
                context.Entry(customer).State = EntityState.Modified;

                //Assert
                Assert.AreEqual(EntityState.Unchanged, context.Entry(address).State, "address State no es Unchanged");

                //Act
                context.SaveChanges();

                context.Entry(address).Reload();

                //Assert
                Assert.AreNotEqual(address.Region, newRegion, $"Region no es {newRegion}");
            }
        }
        public void Manage_EntityWithState()
        {
            //Arrange
            Country country;
            using (var context = new ManagementContext())
            {
                country = context.Countries.First();
            }
            var customer = new Customer()
            {
                State = State.Added,
                Name = "Nuevo cliente",                
                Addresses = new Collection<Address>()
                {
                    new Address()
                    {
                        State = State.Added,
                        Region = "Nueva región 1",
                        CountryId = country.Id,
                        Country = country,                        
                    }
                    ,
                    new Address()
                    {
                        State = State.Added,
                        Region = "Nueva región 2",
                        CountryId = country.Id,
                    }
                    ,
                    new Address()
                    {
                        State = State.Added,
                        Region = "Nueva región 3",
                        Country = country,
                    }
                }
            };

            using (var context = new ManagementContext())
            {
                context.Customers.Add(customer);

                //Act
                context.ApplyStateChanges();

                //Assert
                Assert.AreEqual(context.Entry(customer).State, EntityState.Added, "customer no es Added");

                var nuevaRegion1 = customer.Addresses.Single(p => p.Region == "Nueva región 1");
                Assert.AreEqual(context.Entry(nuevaRegion1).State, EntityState.Added, "address no es Added");
                Assert.AreEqual(context.Entry(nuevaRegion1.Country).State, EntityState.Unchanged, "country no es Unchanged");
                Assert.IsNotNull(nuevaRegion1.Country, "country es null");

                var nuevaRegion2 = customer.Addresses.Single(p => p.Region == "Nueva región 2");
                Assert.IsNotNull(nuevaRegion2.Country, "country es null");

                var nuevaRegion3 = customer.Addresses.Single(p => p.Region == "Nueva región 3");
                Assert.AreNotEqual(nuevaRegion3.CountryId, 0, "CountryId es 0");
            }
        }
        public List <AppUser> GetAllNonAdmin()
        {
            //select* from AspNetUsers inner join AspNetUserRoles
            //on AspNetUsers.Id = AspNetUserRoles.UserId
            //inner join AspNetRoles
            //on AspNetUserRoles.RoleId = AspNetRoles.Id
            //where AspNetRoles.Name = 'Member'


            using var context = new ManagementContext();

            return(context.Users.Join(context.UserRoles, user => user.Id, userRole => userRole.UserId, (resultUser, resultUserRole) => new
            {
                user = resultUser,
                userRole = resultUserRole
            }).Join(context.Roles, twoTableResult => twoTableResult.userRole.RoleId, role => role.Id, (resultTable, resultRole) => new
            {
                user = resultTable.user,
                userRoles = resultTable.userRole,
                roles = resultRole
            }).Where(x => x.roles.Name == "Member").Select(x => new AppUser()
            {
                Id = x.user.Id,
                Name = x.user.Name,
                Surname = x.user.Surname,
                Picture = x.user.Picture,
                Email = x.user.Email,
                UserName = x.user.UserName
            }).ToList());
        }
 public CreateOrderWorkflowStep(ManagementContext context, Organization beneficiary, Product product, Organization payer)
     : base(context)
 {
     this.beneficiary = beneficiary;
     this.product = product;
     this.payer = payer;
 }
        public void Setup()
        {
            var emp = new List <Students>
            {
                new Students {
                    Class = 6, Name = "Dummy 1", RollNo = 1, Age = 12
                },
                new Students {
                    Class = 5, Name = "Dummy 2", RollNo = 5, Age = 14
                },
                new Students {
                    Class = 8, Name = "Dummy 3", RollNo = 4, Age = 16
                },
            };

            var empdata = emp.AsQueryable();
            var mockSet = new Mock <DbSet <Students> >();

            mockSet.As <IQueryable <Students> >().Setup(m => m.Provider).Returns(empdata.Provider);
            mockSet.As <IQueryable <Students> >().Setup(m => m.Expression).Returns(empdata.Expression);
            mockSet.As <IQueryable <Students> >().Setup(m => m.ElementType).Returns(empdata.ElementType);
            mockSet.As <IQueryable <Students> >().Setup(m => m.GetEnumerator()).Returns(empdata.GetEnumerator());

            var mockContext = new Mock <ManagementContext>();

            mockContext.Setup(c => c.Students).Returns(mockSet.Object);
            db = mockContext.Object;
        }
Exemplo n.º 7
0
        public static ManagementContext Build()
        {
            var rtn = new ManagementContext();

            var swis = new Application { Name = "SWIS" };
            var cico = new Application { Name = "CICO" };
            var isis = new Application { Name = "ISIS" };

            var trainingProduct = new Product { Name = "SWIS Training" };
            var swisSubscription = new Product { Name = "SWIS Subscription", Application = swis };
            var cicoSubscription = new Product { Name = "CICO Subscription", Application = cico };
            var isisSubscription = new Product { Name = "ISIS Subscription", Application = isis };

            var hogwarts = new Organization { Name = "Hogwarts" };
            var starfleet = new Organization { Name = "Starfleet Academy" };

            var hogwartsFinancial = new FinancialAccount { Organization = hogwarts };

            rtn.Applications.Add(swis);
            rtn.Applications.Add(cico);
            rtn.Applications.Add(isis);

            rtn.Products.Add(trainingProduct);
            rtn.Products.Add(swisSubscription);
            rtn.Products.Add(cicoSubscription);
            rtn.Products.Add(isisSubscription);

            rtn.Organizations.Add(hogwarts);
            rtn.Organizations.Add(starfleet);

            rtn.FinancialAccounts.Add(hogwartsFinancial);

            return rtn;
        }
        public List <AppUser> GetAllNonAdmin(out int pageCount, string searchKey, int activePage = 1)
        {
            using var context = new ManagementContext();

            var result = context.Users.Join(context.UserRoles, user => user.Id, userRole => userRole.UserId, (resultUser, resultUserRole) => new
            {
                user     = resultUser,
                userRole = resultUserRole
            }).Join(context.Roles, twoTableResult => twoTableResult.userRole.RoleId, role => role.Id, (resultTable, resultRole) => new
            {
                user      = resultTable.user,
                userRoles = resultTable.userRole,
                roles     = resultRole
            }).Where(x => x.roles.Name == "Member").Select(x => new AppUser()
            {
                Id       = x.user.Id,
                Name     = x.user.Name,
                Surname  = x.user.Surname,
                Picture  = x.user.Picture,
                Email    = x.user.Email,
                UserName = x.user.UserName
            });

            pageCount = (int)Math.Ceiling((double)result.Count() / 4);

            if (!string.IsNullOrWhiteSpace(searchKey))
            {
                result    = result.Where(x => x.Name.ToLower().Contains(searchKey.ToLower()) || x.Surname.ToLower().Contains(searchKey.ToLower()));
                pageCount = (int)Math.Ceiling((double)result.Count() / 4);
            }

            result = result.Skip((activePage - 1) * 4).Take(4);

            return(result.ToList());
        }
 public void SetUp()
 {
     using (var context = new ManagementContext())
     {
         context.Database.Initialize(true);
     }
 }
        private AzureManagement InitialiseScriptPack()
        {
            _configurationManager.AddProvider(new ScriptArgsConfigurationProvider(_scriptArgs));
            _configurationManager.Initialise();

            _credentialManager.Initialise();

            _httpTracingInterceptor = new HttpTracingInterceptor(_logger, isEnabled: ConfigurationManager.Config.HttpTraceEnabled);
            CloudContext.Configuration.Tracing.AddTracingInterceptor(_httpTracingInterceptor);

            var managementContext = new ManagementContext
            {
                Logger            = _logger,
                CredentialManager = _credentialManager
            };

            _computeManagement        = new Lazy <ComputeManagement>(() => new ComputeManagement(managementContext));
            _infrastructureManagement = new Lazy <InfrastructureManagement>(() => new InfrastructureManagement(managementContext));
            _monitoringManagement     = new Lazy <MonitoringManagement>(() => new MonitoringManagement(managementContext));
            _mediaManagement          = new Lazy <MediaManagement>(() => new MediaManagement(managementContext));
            _schedulerManagement      = new Lazy <SchedulerManagement>(() => new SchedulerManagement(managementContext));
            _serviceBusManagement     = new Lazy <ServiceBusManagement>(() => new ServiceBusManagement(managementContext));
            _sqlManagement            = new Lazy <SqlManagement>(() => new SqlManagement(managementContext));
            _storageManagement        = new Lazy <StorageManagement>(() => new StorageManagement(managementContext));
            _virtualNetworkManagement = new Lazy <VirtualNetworkManagement>(() => new VirtualNetworkManagement(managementContext));
            _webSiteManagement        = new Lazy <WebSiteManagement>(() => new WebSiteManagement(managementContext));

            return(this);
        }
        public void Setup()
        {
            var emp = new List <Attendance>
            {
                new Attendance {
                    RollNo = 1, Attendance1 = "32", Result = 45
                },
                new Attendance {
                    RollNo = 3, Attendance1 = "52", Result = 86
                },
                new Attendance {
                    RollNo = 1, Attendance1 = "29", Result = 96
                },
            };

            var salData = emp.AsQueryable();
            var mockSet = new Mock <DbSet <Attendance> >();

            mockSet.As <IQueryable <Attendance> >().Setup(m => m.Provider).Returns(salData.Provider);
            mockSet.As <IQueryable <Attendance> >().Setup(m => m.Expression).Returns(salData.Expression);
            mockSet.As <IQueryable <Attendance> >().Setup(m => m.ElementType).Returns(salData.ElementType);
            mockSet.As <IQueryable <Attendance> >().Setup(m => m.GetEnumerator()).Returns(salData.GetEnumerator());

            var mockContext = new Mock <ManagementContext>();

            mockContext.Setup(c => c.Attendance).Returns(mockSet.Object);
            db = mockContext.Object;
        }
 public CreateOrderWorkflowStep(ManagementContext context, Organization beneficiary, Product product, Organization payer)
     : base(context)
 {
     this.beneficiary = beneficiary;
     this.product     = product;
     this.payer       = payer;
 }
Exemplo n.º 13
0
        public void DbSet_Add_Set_All_Graph_Added()
        {
            //Assert
            Country country;

            using (var context = new ManagementContext())
            {
                country = context.Countries.First();
            }
            var customer = new Customer
            {
                Name      = "Nuevo cliente",
                Addresses = new Collection <Address>()
                {
                    new Address()
                    {
                        Region = "Nueva región", Country = country
                    }
                }
            };

            //Act
            using (var context = new ManagementContext())
            {
                context.Customers.Add(customer);

                //Assert
                Assert.AreEqual(EntityState.Added, context.Entry(country).State, "country State no es Added");

                context.SaveChanges();

                Assert.AreEqual(3, context.Countries.Count(), "Countries no son 3");
            }
        }
        public void DbSet_Add_Set_All_Graph_Added()
        {
            //Assert
            Country country;
            using (var context = new ManagementContext())
            {
                country = context.Countries.First();
            }
            var customer = new Customer
            {
                Name = "Nuevo cliente",
                Addresses = new Collection<Address>()
                {
                    new Address() { Region = "Nueva región", Country = country }
                }
            };

            //Act
            using (var context = new ManagementContext())
            {
                context.Customers.Add(customer);

                //Assert
                Assert.AreEqual(EntityState.Added, context.Entry(country).State, "country State no es Added");

                context.SaveChanges();

                Assert.AreEqual(3, context.Countries.Count(), "Countries no son 3");
            }
        }
        public void DbEntityEntry_State_Modified_Only_Set_Current_Entity()
        {
            //Assert
            var customer = GetFirstDisconnectedCustomerFullyLoaded();
            customer.Name = "Cliente modificado";

            var address = customer.Addresses.First();
            const string newRegion = "Región modificada";
            address.Region = newRegion;

            using (var context = new ManagementContext())
            {
                //Act
                context.Entry(customer).State = EntityState.Modified;

                //Assert
                Assert.AreEqual(EntityState.Unchanged, context.Entry(address).State, "address State no es Unchanged");

                //Act
                context.SaveChanges();

                context.Entry(address).Reload();

                //Assert
                Assert.AreNotEqual(address.Region, newRegion, $"Region no es {newRegion}");
            }
        }
        public IEnumerable <Owner> Search(string searchString, ManagementContext context)
        {
            var partialString = searchString.Split(" ");
            var owners        = Enumerable.Empty <Owner>().AsQueryable();

            switch (searchString)
            {
            // Checks DoB pattern
            case var someVal when Regex.IsMatch(searchString, @"^\d{6,11}.?(\d{4})?"):

                return(context.Owners.Where(o => o.SSN.Contains(searchString)));

            case var someVal when Regex.IsMatch(searchString, @"[\w.\w]*@{1}[\w.\w]*[\w.\w{2,3}]$"):

                return(context.Owners.Where(o => o.Mail == searchString));

            default:

                return(context.Owners.Where(o => o.FirstName.Contains(searchString) ||
                                            o.LastName.Contains(searchString) ||
                                            o.Address.Contains(searchString) ||
                                            o.Mail.Contains(searchString))
                       .Distinct());
            }
        }
Exemplo n.º 17
0
        public int GetUserReportCount(int id)
        {
            using var context = new ManagementContext();

            var result = context.Works.Include(x => x.Reports).Where(x => x.AppUserId == id);

            return(result.SelectMany(x => x.Reports).Count());
        }
Exemplo n.º 18
0
        protected WorkflowBase(ManagementContext db)
        {
            this.db    = db;
            this.steps = new List <WorkflowStepWrapper>();

            this.availableParams  = new List <Tuple <string, Type, int> >();
            this.paramsWithValues = new List <Tuple <string, Type, object> >();
        }
Exemplo n.º 19
0
        protected WorkflowBase(ManagementContext db)
        {
            this.db = db;
            this.steps = new List<WorkflowStepWrapper>();

            this.availableParams = new List<Tuple<string, Type, int>>();
            this.paramsWithValues = new List<Tuple<string, Type, object>>();
        }
Exemplo n.º 20
0
        public HomeController(ManagementContext ctx, IStringLocalizerFactory factory) : base(factory)
        {
            ctx.Database.EnsureCreated();

            var service = new GenericService(ctx);

            _service = new EquipmentRequestHandler(service);
        }
 protected static Customer GetFirstDisconnectedCustomerFullyLoaded()
 {
     Customer customer;
     using (var context = new ManagementContext())
     {
         customer = GetFirstCustomerFullyLoaded(context);
     }
     return customer;
 }
Exemplo n.º 22
0
        public MonitoringManagement(ManagementContext managementContext)
        {
            _logger            = managementContext.Logger;
            _credentialManager = managementContext.CredentialManager;

            _alerts    = new Lazy <MonitoringManagementAlerts>(() => new MonitoringManagementAlerts(managementContext));
            _autoscale = new Lazy <MonitoringManagementAutoscale>(() => new MonitoringManagementAutoscale(managementContext));
            _metrics   = new Lazy <MonitoringManagementMetrics>(() => new MonitoringManagementMetrics(managementContext));
        }
Exemplo n.º 23
0
        static void Main(string[] args)
        {
            var context = new ManagementContext();
            IStudentRepository studentRepository = new StudentRepository(context, new Log4NetTracer());
            ICourseRepository  courseRepository  = new CourseRepository(context, new Log4NetTracer());

            IStudentAffairs affairs = new StudentAffairs(studentRepository, courseRepository);

            affairs.RegisterToCourse(1, 1);
        }
Exemplo n.º 24
0
        protected static Customer GetFirstDisconnectedCustomerFullyLoaded()
        {
            Customer customer;

            using (var context = new ManagementContext())
            {
                customer = GetFirstCustomerFullyLoaded(context);
            }
            return(customer);
        }
Exemplo n.º 25
0
        public List <Work> GetWithAllTablesNotCompleted(out int pageCount, int userId, int activePage = 1)
        {
            using var context = new ManagementContext();
            var result = context.Works.Include(x => x.Urgency).Include(x => x.Reports).Include(x => x.AppUser)
                         .Where(x => x.AppUserId == userId && x.Status).OrderByDescending(x => x.CreatedTime);

            pageCount = (int)Math.Ceiling((double)result.Count() / 3);

            return(result.Skip((activePage - 1) * 3).Take(3).ToList());
        }
Exemplo n.º 26
0
        public static ManagementContext Build()
        {
            var rtn = new ManagementContext();

            var swis = new Application {
                Name = "SWIS"
            };
            var cico = new Application {
                Name = "CICO"
            };
            var isis = new Application {
                Name = "ISIS"
            };

            var trainingProduct = new Product {
                Name = "SWIS Training"
            };
            var swisSubscription = new Product {
                Name = "SWIS Subscription", Application = swis
            };
            var cicoSubscription = new Product {
                Name = "CICO Subscription", Application = cico
            };
            var isisSubscription = new Product {
                Name = "ISIS Subscription", Application = isis
            };

            var hogwarts = new Organization {
                Name = "Hogwarts"
            };
            var starfleet = new Organization {
                Name = "Starfleet Academy"
            };

            var hogwartsFinancial = new FinancialAccount {
                Organization = hogwarts
            };

            rtn.Applications.Add(swis);
            rtn.Applications.Add(cico);
            rtn.Applications.Add(isis);

            rtn.Products.Add(trainingProduct);
            rtn.Products.Add(swisSubscription);
            rtn.Products.Add(cicoSubscription);
            rtn.Products.Add(isisSubscription);

            rtn.Organizations.Add(hogwarts);
            rtn.Organizations.Add(starfleet);

            rtn.FinancialAccounts.Add(hogwartsFinancial);

            return(rtn);
        }
Exemplo n.º 27
0
        public void ConfigureProduction(IApplicationBuilder app,
                                        IHostingEnvironment env,
                                        ILoggerFactory loggerFactory,
                                        ManagementContext managementContext)
        {
            Configure(app, env);

            //Seed Data
            ManagementContextSeed.SeedAsync(app, managementContext, loggerFactory)
            .Wait();
        }
        public List <DualHelper> MostEmployeedAtWork()
        {
            using var context = new ManagementContext();

            return(context.Works.Include(x => x.AppUser).Where(x => !x.Status && x.AppUserId != null)
                   .GroupBy(x => x.AppUser.Name + " " + x.AppUser.Surname).OrderByDescending(x => x.Count()).Take(5).Select(x => new DualHelper
            {
                Name = x.Key,
                WorkCount = x.Count()
            }).ToList());
        }
        //        select AspNetUsers.UserName, count(works.Id) from AspNetUsers inner join Works on AspNetUsers.Id = Works.AppUserId
        //where Works.Status = 1 group by AspNetUsers.UserName

        public List <DualHelper> Top5WorkCompleter()
        {
            using var context = new ManagementContext();

            return(context.Works.Include(x => x.AppUser).Where(x => x.Status == true)
                   .GroupBy(x => x.AppUser.Name + " " + x.AppUser.Surname).OrderByDescending(x => x.Count()).Take(5).Select(x => new DualHelper
            {
                Name = x.Key,
                WorkCount = x.Count()
            }).ToList());
        }
        public PlaceOrderWorkflow(ManagementContext db, Organization beneficiary, Product product, Organization payer)
            : base(db)
        {
            var orderStep = new CreateOrderWorkflowStep(db, beneficiary, product, payer);
            this.Add(orderStep, 1);

            if (product.Application != null)
            {
                var subStep = new AddSubscriptionWorkflowStep(db, beneficiary, product.Application);
                this.Add(subStep, 2);
            }
        }
Exemplo n.º 31
0
        protected void Session_Start(object sender, EventArgs e)
        {
            //TODO: esto pa que hay que hacerlo?
            var db = new ManagementContext();

            db.Database.Initialize(true);
            db.Database.CreateIfNotExists();


            //TODO: usamos esto?
            Session["idUser"] = null;
        }
        public PlaceOrderWorkflow(ManagementContext db, Organization beneficiary, Product product, Organization payer)
            : base(db)
        {
            var orderStep = new CreateOrderWorkflowStep(db, beneficiary, product, payer);

            this.Add(orderStep, 1);

            if (product.Application != null)
            {
                var subStep = new AddSubscriptionWorkflowStep(db, beneficiary, product.Application);
                this.Add(subStep, 2);
            }
        }
        public void GetAll_DTO_Success()
        {
            //Arrange
            using (var context = new ManagementContext())
            {
                var unitOfWork         = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);
                var sut = new CustomersService(customerRepository);

                Mapper.CreateMap <Customer, CustomerDTO>()
                .ForMember(dst => dst.CustomerId, opt => opt.MapFrom(src => src.Id));

                Assert.Greater(sut.GetAll_DTO("C").Count(), 0);
            }
        }
        public void GetAll_DTO_Success()
        {
            //Arrange
            using (var context = new ManagementContext())
            {
                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);
                var sut = new CustomersService(customerRepository);

                Mapper.CreateMap<Customer, CustomerDTO>()
                    .ForMember(dst => dst.CustomerId, opt => opt.MapFrom(src => src.Id));

                Assert.Greater(sut.GetAll_DTO("C").Count(), 0);
            }
        }
 private void InsertCustomers(int count)
 {
     using (var context = new ManagementContext())
     {
         for (int i = 0; i < count; i++)
         {
             context.Customers.Add(new Customer()
             {
                 Name = "Cliente " + i,
                 Code = "C" + i
             });
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 36
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ManagementContext managementContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
        public void GetAllWithPredicate_Customer_Succeed()
        {
            //Arrange
            InsertCustomers(20);

            using (var context = new ManagementContext())
            {
                var unitOfWork         = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                var total = customerRepository.GetAll(CustomerRepository.Predicates(p => p.Id > 5), null).Count();

                //Assert
                Assert.AreEqual(15, total);
            }
        }
Exemplo n.º 38
0
        public void When_Connected_Graph_Is_Modified_ChangeTracker_Is_Aware_For_All_Entities()
        {
            using (var context = new ManagementContext())
            {
                //Arrange
                var customer = GetFirstCustomerFullyLoaded(context);

                //Act
                customer.Name = "Cliente modificado";
                var address = customer.Addresses.First();
                address.Region = "Región modificada";

                //Assert
                Assert.IsTrue(context.Entry(customer).Property(p => p.Name).IsModified, "Name no está modificado");
                Assert.IsTrue(context.Entry(address).Property(p => p.Region).IsModified, "Region no está modificada");
            }
        }
        public void DbSet_Attach_If_Foreign_Keys_Are_Invalid_Throw_Exception()
        {
            //Assert
            var customer = GetFirstDisconnectedCustomerFullyLoaded();

            var country = new Country() { Name = "Nuevo país" };
            customer.Addresses.First().Country = country;

            using (var context = new ManagementContext())
            {
                //Assert
                Assert.AreNotEqual(country.Id, customer.Addresses.First().CountryId);

                //Act
                context.Customers.Attach(customer);
            }
        }
        public void GetAll_Customer_Succeed()
        {
            //Arrange
            InsertCustomers(20);

            using (var context = new ManagementContext())
            {
                var unitOfWork         = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                var total = customerRepository.GetAll().Count();

                //Assert
                Assert.AreEqual(20, total);
            }
        }
Exemplo n.º 41
0
        public async Task <bool> checkToken(string username, string token)
        {
            using (var db = new ManagementContext())
            {
                ManagementModel model = await db.management
                                        .Where(x => x.username == username)
                                        .SingleAsync();

                if (model.token == token)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        public void Remove_Customer_Succeed()
        {
            using (var context = new ManagementContext())
            {
                //Arrange
                var total = context.Customers.Count();
                var customer = context.Customers.First();
                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                customerRepository.Remove(customer);
                unitOfWork.Save();

                //Assert
                Assert.AreEqual(context.Customers.Count(), total - 1);
            }
        }
        public void Save_Customer_Succeed()
        {
            using (var context = new ManagementContext())
            {
                //Arrange
                var customer = context.Customers.First();
                customer.Name = "Cliente modificado";

                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                customerRepository.Save(customer);
                unitOfWork.Save();

                //Assert
                Assert.Pass();
            }
        }
        public void Save_NewCustomer_Succeed()
        {
            using (var context = new ManagementContext())
            {
                //Arrange                
                var customer = new Customer()
                {
                    Name = "Nuevo cliente"
                };
                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                customerRepository.Save(customer);
                unitOfWork.Save();

                //Assert
                Assert.Pass();
            }
        }
Exemplo n.º 45
0
        public static bool SaveCurrentPaypalBitcoinInformation(Fund fund)
        {

            var dc = new ManagementContext();
            var funds = dc.Funds.Where(x => x.UserId == fund.UserId).FirstOrDefault();
            if (funds == null)
            {
                FundsForWriter f = new FundsForWriter();
                f.BitCoinId = fund.BitCoinId;
                f.PaypalAddress = fund.PaypalAddress;
                f.UserId = fund.UserId;
                dc.Funds.Add(f);
            }
            else
            {
                funds.PaypalAddress = fund.PaypalAddress;
                funds.BitCoinId = fund.BitCoinId;
            }
            int c = dc.SaveChanges();

            return c > 0;
        }
Exemplo n.º 46
0
        public static Fund GetCurrentFundsInformation(Guid userId)
        {
            Fund f = new Fund();

            var dc = new ManagementContext();
            var funds = dc.Funds.Where(x => x.UserId == userId).FirstOrDefault();
            if (funds == null)
            {
                f.ActiveInUserAccount = 0.00;
                f.AmountToWithdraw = 0.00;
                f.TotalPaidToUser = 0.00;
            }
            else
            {
                f.AmountToWithdraw = funds.ActiveInUserAccount;
                f.ActiveInUserAccount = funds.ActiveInUserAccount;
                f.TotalPaidToUser = funds.TotalPaidToUser;
                f.BitCoinId = funds.BitCoinId;
                f.PaypalAddress = funds.PaypalAddress;
            }
            f.UserId = userId;

            return f;
        }
Exemplo n.º 47
0
 public LocatorBase(ManagementContext db)
 {
     this.db = db;
 }
        public void GetPaginated_Customer_Succeed(PaginatedData paginatedData)
        {
            //Arrange            
            using (var context = new ManagementContext())
            {
                var executor = new SqlExecutor(context.Database.Connection.ConnectionString);
                executor.ExecuteScript(Path.Combine(Environment.CurrentDirectory, "Scripts", "2 - Customers.sql"));

                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                PaginatedResult<Customer> result = customerRepository.GetPaginated(null, null, p => p.Id, paginatedData.PageIndex, paginatedData.PageSize);

                //Assert
                Assert.AreEqual(paginatedData.ResultCount, result.Result.Count());
                Assert.AreEqual(paginatedData.PageIndex, result.PageIndex);
                Assert.AreEqual(paginatedData.PageSize, result.PageSize);
                Assert.AreEqual(paginatedData.TotalCount, result.TotalCount);
                Assert.AreEqual(paginatedData.TotalPageCount, result.TotalPageCount);
                Assert.AreEqual(paginatedData.HasPreviousPage, result.HasPreviousPage);
                Assert.AreEqual(paginatedData.HasNextPage, result.HasNextPage);
            }
        }
 protected static Customer GetFirstCustomerFullyLoaded(ManagementContext context)
 {
     return context.Customers
         .Include(p => p.Addresses)
         .Include(p => p.Addresses.Select(t => t.Country)).First();
 }
        public void GetAllWithPredicates_Customer_Succeed()
        {
            //Arrange            
            using (var context = new ManagementContext())
            {
                var executor = new SqlExecutor(context.Database.Connection.ConnectionString);
                executor.ExecuteScript(Path.Combine(Environment.CurrentDirectory, "Scripts", "2 - Customers.sql"));

                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                var predicates = CustomerRepository.Predicates(p => p.Id > 2, p => p.Code.StartsWith("A"));
                var total = customerRepository.GetAll<Customer>(predicates, null, null).Count();

                //Assert
                Assert.AreEqual(3, total);
            }
        }
        public void GetAllWithPredicate_Customer_Succeed()
        {
            //Arrange
            InsertCustomers(20);

            using (var context = new ManagementContext())
            {
                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                var total = customerRepository.GetAll(CustomerRepository.Predicates(p => p.Id > 5), null).Count();

                //Assert
                Assert.AreEqual(15, total);
            }
        }
        public void GetAll_Customer_Succeed()
        {
            //Arrange
            InsertCustomers(20);

            using (var context = new ManagementContext())
            {
                var unitOfWork = new DatabaseUnitOfWork(context);
                var customerRepository = new CustomerRepository(unitOfWork);

                //Act
                var total = customerRepository.GetAll().Count();

                //Assert
                Assert.AreEqual(20, total);
            }
        }
        public void DbEntityEntry_State_Modified_If_Foreign_Keys_Are_Invalid_Throw_Exception()
        {
            //Assert
            var customer = GetFirstDisconnectedCustomerFullyLoaded();

            var country = new Country() { Name = "Nuevo país" };
            customer.Addresses.First().Country = country;

            using (var context = new ManagementContext())
            {
                //Assert
                Assert.AreNotEqual(country.Id, customer.Addresses.First().CountryId);

                //Act
                context.Entry(customer).State = EntityState.Modified;
            }
        }
 protected WorkflowStepBase(ManagementContext context)
 {
     this.Context = context;
 }
 public AddSubscriptionWorkflowStep(ManagementContext context, Organization subscriber, Application application)
     : base(context)
 {
     this.subscriber = subscriber;
     this.application = application;
 }
 private void InsertCustomers(int count)
 {
     using (var context = new ManagementContext())
     {
         for (int i = 0; i < count; i++)
         {
             context.Customers.Add(new Customer()
             {
                 Name = "Cliente " + i,
                 Code = "C" + i
             });
         }
         context.SaveChanges();
     }
 }
 public FinancialAccountLocater(ManagementContext db)
     : base(db)
 {
 }