コード例 #1
0
        private (int, int?, int?) Create()
        {
            // Arrange
            var order = new Order
            {
                Id     = _id,
                Number = _number,
                Date   = _date,
                Total  = _total,
                //UserId = _userId,
                //User = new User() { Id = (int)_userId },
                DeliveryId = _deliveryId,
                Delivery   = new Delivery()
                {
                    Id = (int)_deliveryId
                },
                DeliveryStatus = _deliveryStatus,
                PaymentStatus  = _paymentStatus
            };

            // Act
            _repository.CreateAsync(order);
            ContextSingleton.GetDatabaseContext().SaveChanges();
            // Assert
            Assert.AreNotEqual(0, order.Id, "Creating new record does not return id");
            return(order.Id, 2, order.DeliveryId);
        }
コード例 #2
0
        private async Task <(string, int?)> CreateAsync()
        {
            // Arrange
            var user = new User
            {
                FirstName = _firstName,
                LastName  = _lastName,
                Address   = new Address {
                    Id = _addressId.Value
                },
                Comments = new List <Comment> {
                    new Comment()
                    {
                        Id = _comment1Id, Date = _dateTime1
                    }, new Comment()
                    {
                        Id = _comment2Id, Date = _dateTime2
                    }
                },
                AddressId   = _addressId,
                PhoneNumber = _phoneNumber,
                Email       = _email
            };
            // Act
            await _repository.CreateAsync(user);

            ContextSingleton.GetDatabaseContext().SaveChanges();

            // Assert
            Assert.AreNotEqual(0, user.Id, "Creating new record does not return id");

            return(user.Id, user.AddressId);
        }
コード例 #3
0
        private (int, int, int) Create()
        {
            // Arrange
            var orderDetails = new OrderDetails
            {
                Id      = _id,
                OrderId = _orderId + 1,
                Order   = new Order()
                {
                    Id = _orderId + 1
                },
                ProductId = _productId + 1,
                Product   = new Product()
                {
                    Id = _productId + 1
                },
                Count = _count
            };

            // Act
            _repository.CreateAsync(orderDetails);
            ContextSingleton.GetDatabaseContext().SaveChanges();
            // Assert
            Assert.AreNotEqual(0, orderDetails.Id, "Creating new record does not return id");
            return(orderDetails.Id, orderDetails.OrderId, orderDetails.ProductId);
        }
コード例 #4
0
        private Delivery Create() //параметры?
        {
            // Arrange
            var delivery = new Delivery
            {
                Id                    = _id,
                Name                  = _name,
                Type                  = _type,
                DeliveryNote          = _deliveryNote,
                Date                  = _date,
                Price                 = _price,
                BranchDeliveryService = _branchDeliveryService,
                AddressId             = _addressId,
                AddressDelivery       = _addressDelivery
            };

            // Act
            _repository.CreateAsync(delivery);
            ContextSingleton.GetDatabaseContext().SaveChanges();

            // Assert
            Assert.AreNotEqual(0, delivery.Id, "Creating new record does not return id");

            return(delivery);
        }
コード例 #5
0
        private async Task <(int, int, string?)> CreateAsync()
        {
            // Arrange
            var comment = new Comment
            {
                Date    = _date,
                Id      = _id,
                Text    = _text,
                Product = new Product {
                    Id = _id
                },
                //User = new User { Id = _userId.Value },
                // Like = _like,
                //Dislike = _dislike,
                UserId = ""
            };
            // Act
            await _repository.CreateAsync(comment);

            await ContextSingleton.GetDatabaseContext().SaveChangesAsync();

            // Assert
            Assert.AreNotEqual(0, comment.Id, "Creating new record does not return id");

            return(comment.Id, comment.ProductId, comment.UserId);
        }
コード例 #6
0
        public void SaveContextValues()
        {
            string _tempReportsPath = HttpContext.Current.Server.MapPath("~/TempReports/");

            string _applicationPath = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath);

            ContextSingleton.InitInstance(_tempReportsPath, _applicationPath);
        }
コード例 #7
0
        private async Task Update(int id)
        {
            // Arrange
            var orderDetails = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            orderDetails.Count = 20;
            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();
            var updatedOrderDetails = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            // Assert
            Assert.AreEqual(20, updatedOrderDetails.Count, "Record is not updated.");
        }
コード例 #8
0
        private async Task UpdateAsync(int id)
        {
            // Arrange
            var comment = (await _repository.FindByConditionAsync(x => x.Id == id));

            //comment.ElementAt(0).UserId = 5;
            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();
            var updatedComment = (await _repository.FindByConditionAsync(x => x.Id == id));

            // Assert
            Assert.AreEqual(5, updatedComment.ElementAtOrDefault(0).UserId, "not updated.");
        }
コード例 #9
0
        private async Task Update(int id)
        {
            // Arrange
            var image = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            image.FilePath = "new file path";

            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();

            var updatedImage = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            // Assert
            Assert.AreEqual("new file path", updatedImage.FilePath, "Record is not updated.");
        }
コード例 #10
0
        private async Task Update(int id)
        {
            // Arrange
            var package = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            package.CountInPackage = 20;
            package.Volume         = 15.15;
            package.Weight         = 33.33;
            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();
            var updatedPackage = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            // Assert
            Assert.AreEqual(20, updatedPackage.CountInPackage, "Record is not updated.");
            Assert.AreEqual(15.15, updatedPackage.Volume, "Record is not updated.");
            Assert.AreEqual(33.33, updatedPackage.Weight, "Record is not updated.");
        }
コード例 #11
0
        private async Task Update(int id)
        {
            // Arrange
            var category = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            category.Title        = "Title";
            category.PreviewImage = "Preview Image";

            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();

            var updatedcategory = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            // Assert
            Assert.AreEqual("Title", updatedcategory.Title, "Record is not updated.");
            Assert.AreEqual("Preview Image", updatedcategory.PreviewImage, "Record is not updated.");
        }
コード例 #12
0
        private async Task Update(int id)
        {
            // Arrange
            var product = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            product.VendorCode = "1234567890";
            product.Model      = "qwerty-333";
            product.Rating     = 5;

            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();
            var updatedproduct = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            // Assert
            Assert.AreEqual("1234567890", updatedproduct.VendorCode, "Record is not updated.");
            Assert.AreEqual(5, updatedproduct.Rating, "Record is not updated.");
            Assert.AreEqual("qwerty-333", updatedproduct.Model, "Record is not updated.");
        }
コード例 #13
0
        private int Create()
        {
            // Arrange
            var package = new Package
            {
                Id             = _id,
                CountInPackage = _countInPackage,
                Volume         = _volume,
                Weight         = _weight
            };

            // Act
            _repository.CreateAsync(package);
            ContextSingleton.GetDatabaseContext().SaveChanges();
            // Assert
            Assert.AreNotEqual(0, package.Id, "Creating new record does not return id");
            return(package.Id);
        }
コード例 #14
0
        private int Create()
        {
            // Arrange
            var category = new Category
            {
                Id           = _id,
                Title        = _title,
                PreviewImage = _previewImage
            };

            // Act
            _repository.CreateAsync(category);
            ContextSingleton.GetDatabaseContext().SaveChanges();

            // Assert
            Assert.AreNotEqual(0, category.Id, "Creating new category does not return id");

            return(category.Id);
        }
コード例 #15
0
        private async Task Update(int id)
        {
            // Arrange
            var brand = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            brand.Country     = "Japan";
            brand.Description = "newDescription";
            brand.Name        = "LG";

            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();

            var updatedBrand = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            // Assert
            Assert.AreEqual("Japan", updatedBrand.Country, "Record is not updated.");
            Assert.AreEqual("newDescription", updatedBrand.Description, "Record is not updated.");
            Assert.AreEqual("LG", updatedBrand.Name, "Record is not updated.");
        }
コード例 #16
0
        private async Task Update(int id)
        {
            // Arrange
            var address = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            address.City            = "Lvov";
            address.ApartmentNumber = "10";
            address.Street          = "Ivanova";

            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();

            var updatedAddress = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            // Assert
            Assert.AreEqual("Lvov", updatedAddress.City, "Record is not updated.");
            Assert.AreEqual("10", updatedAddress.ApartmentNumber, "Record is not updated.");
            Assert.AreEqual("Ivanova", updatedAddress.Street, "Record is not updated.");
        }
コード例 #17
0
        private int Create()
        {
            // Arrange
            var brand = new Brand
            {
                Id          = _id,
                Country     = _country,
                Name        = _name,
                Description = _description
            };

            // Act
            _repository.CreateAsync(brand);
            ContextSingleton.GetDatabaseContext().SaveChanges();

            // Assert
            Assert.AreNotEqual(0, brand.Id, "Creating new record does not return id");

            return(brand.Id);
        }
コード例 #18
0
        private (int, int) Create()
        {
            // Arrange
            var image = new Image
            {
                Id       = _id,
                FilePath = _filePath,
                Product  = new Product {
                    Id = _id
                }
            };

            // Act
            _repository.CreateAsync(image);
            ContextSingleton.GetDatabaseContext().SaveChanges();

            // Assert
            Assert.AreNotEqual(0, image.Id, "Creating new record does not return id");

            return(image.Id, image.Id);
        }
コード例 #19
0
        private async Task Update(int id)
        {
            // Arrange
            var order = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            order.Number         = "New Number";
            order.Date           = _date.AddDays(20);
            order.Total          = 50;
            order.DeliveryStatus = "New delivery status";
            order.PaymentStatus  = "New payment status";
            // Act
            ContextSingleton.GetDatabaseContext().SaveChanges();
            var updatedOrder = (await _repository.FindByConditionAsync(x => x.Id == id)).FirstOrDefault();

            // Assert
            Assert.AreEqual("New Number", updatedOrder.Number, "Record is not updated.");
            Assert.AreEqual(_date.AddDays(20), updatedOrder.Date, "Record is not updated.");
            Assert.AreEqual(50, updatedOrder.Total, "Record is not updated.");
            Assert.AreEqual("New delivery status", updatedOrder.DeliveryStatus, "Record is not updated.");
            Assert.AreEqual("New payment status", updatedOrder.PaymentStatus, "Record is not updated.");
        }
コード例 #20
0
        private (int, int?, int, int?) Create()
        {
            // Arrange
            var product = new Product
            {
                Id             = _id,
                Title          = _Title,
                Type           = _Type,
                VendorCode     = _VendorCode,
                Description    = _Description,
                RetailPrice    = _RetailPrice,
                PreviewImage   = _PreviewImage,
                CountInStorage = _CountInStorage,
                Rating         = _Rating,
                Series         = _Series,
                WarrantyMonth  = _WarrantyMonth,
                Model          = _Model,
                Brand          = new Brand {
                    Id = (int)_BrandId + 1
                },
                BrandId  = (int)_BrandId + 1,
                Category = new Category {
                    Id = _CategoryId + 1
                },
                CategoryId = _CategoryId + 1,
                Package    = new Package {
                    Id = _PackageId + 1
                },
                PackageId = _PackageId + 1
            };

            // Act
            _repository.CreateAsync(product);
            ContextSingleton.GetDatabaseContext().SaveChanges();

            // Assert
            Assert.AreNotEqual(0, product.Id, "Creating new record does not return id");

            return(product.Id, product.BrandId, product.CategoryId, product.PackageId);
        }
コード例 #21
0
        private int Create()
        {
            // Arrange
            var address = new Address
            {
                Id              = _id,
                Country         = _country,
                City            = _city,
                Street          = _street,
                BuildingNumber  = _buildingNumber,
                ApartmentNumber = _apartmentNumber
            };

            // Act
            _repository.CreateAsync(address);
            ContextSingleton.GetDatabaseContext().SaveChanges();

            // Assert
            Assert.AreNotEqual(0, address.Id, "Creating new record does not return id");

            return(address.Id);
        }
コード例 #22
0
 public EditPostWindow(ContextSingleton context)
 {
     Context = context;
     InitializeComponent();
 }
コード例 #23
0
ファイル: ToDoRepository.cs プロジェクト: genusB/ToDoApp
 public ToDoRepository()
 {
     Context = ContextSingleton.GetInstance();
     Set     = Context.Set <T>();
 }
コード例 #24
0
        /// <summary>
        /// Se controla que el recurso solicitado (a tracés de un end-point) este permitido
        /// para el usuario actual autenticado.
        /// </summary>
        /// <param name="actionContext"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public override Task OnAuthorizationAsync(HttpActionContext actionContext, System.Threading.CancellationToken cancellationToken)
        {
            ContextSingleton.InitBaseUrl();

            var principal = actionContext.RequestContext.Principal as ClaimsPrincipal;

            // Para endpoints con atributo AllowAnonymous evitamos la autenticación.

            bool skipAuthorization =
                actionContext.ActionDescriptor.GetCustomAttributes <AllowAnonymousAttribute>().Any() ||
                actionContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes <AllowAnonymousAttribute>().Any();

            if (skipAuthorization)
            {
                return(Task.FromResult <object>(null));
            }

            //Validación interna contra token.

            if (!principal.Identity.IsAuthenticated)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
                return(Task.FromResult <object>(null));
            }

            //Validación de control de cambio de usuario por fuera de la aplicación.

            var userCookie = HttpContext.Current.Request.Cookies["CiDi"];

            if (userCookie == null)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.NotFound);
            }

            //bool huboCambioDeUsuario = true;

            //UsuarioCidiDto usuarioCidi = UsuarioCidiFactory.ValidarUsuarioCidi();
            //if (usuarioCidi != null)
            //{
            //    LoguinCidiQuery query = new LoguinCidiQuery
            //    {
            //        Cuil = usuarioCidi.Cuil
            //    };

            //    QueryDispatcher _QueryDispatcher = ServiceLocator.Current.GetInstance<QueryDispatcher>();
            //    LoguinCidiQueryResult queryResult = _QueryDispatcher.Dispatch<LoguinCidiQuery, LoguinCidiQueryResult>(query);

            //    if (queryResult.UsuarioDto != null && queryResult.UsuarioDto.Id != null)
            //    {

            //        if (queryResult.UsuarioDto.Cuil == usuarioCidi.Cuil)
            //        {
            //            huboCambioDeUsuario = false;
            //        }
            //    }
            //}

            //if(huboCambioDeUsuario)
            //{
            //    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.NotFound);
            //}

            //Validación de autorización (verifica si el usuario tiene permisos contra URLs)

            if (GlobalVars.AuthenticationByRouteController)
            {
                string endPointAbsolutePath = actionContext.Request.RequestUri.AbsolutePath;
                int    index = endPointAbsolutePath.ToLower().IndexOf("/api/");

                if (index != -1)
                {
                    // Verifico con el listado de end-points disponibles del usuario autenticado.
                    if (principal.Claims.Count() == 0)
                    {
                        actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden);
                        //actionContext.Response.Headers.Add("X-Error", "gob-permiso-denegado");
                        return(Task.FromResult <object>(null));
                    }
                    string         usuario         = principal.Claims.ToList()[1].ToString();
                    UsuarioCidiDto usuarioLogueado = JsonConvert.DeserializeObject <UsuarioCidiDto>(usuario.Substring(6));

                    string perfilId = "";
                    if (!FuncionalidadesSingleton.Instance.tienePermisos(usuarioLogueado.IdRol.ToString(), endPointAbsolutePath.Substring(4)))
                    {
                        actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Forbidden);
                        //actionContext.Response.Headers.Add("X-Error", "gob-permiso-denegado");
                        return(Task.FromResult <object>(null));
                    }
                }
            }

            return(Task.FromResult <object>(null));
        }
コード例 #25
0
 public EfRepository()
 {
     _context = ContextSingleton.GetInstance();
     _set     = _context.Set <T>();
 }
コード例 #26
0
 public void Refresh()
 {
     _context = ContextSingleton.GetInstance();
     _set     = _context.Set <T>();
 }
コード例 #27
0
 public static void RefreshContext()
 {
     ContextSingleton.RefreshContext();
 }