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); }
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); }
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); }
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); }
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); }
public void SaveContextValues() { string _tempReportsPath = HttpContext.Current.Server.MapPath("~/TempReports/"); string _applicationPath = HttpContext.Current.Request.MapPath(HttpContext.Current.Request.ApplicationPath); ContextSingleton.InitInstance(_tempReportsPath, _applicationPath); }
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."); }
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."); }
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."); }
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."); }
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."); }
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."); }
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); }
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); }
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."); }
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."); }
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); }
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); }
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."); }
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); }
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); }
public EditPostWindow(ContextSingleton context) { Context = context; InitializeComponent(); }
public ToDoRepository() { Context = ContextSingleton.GetInstance(); Set = Context.Set <T>(); }
/// <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)); }
public EfRepository() { _context = ContextSingleton.GetInstance(); _set = _context.Set <T>(); }
public void Refresh() { _context = ContextSingleton.GetInstance(); _set = _context.Set <T>(); }
public static void RefreshContext() { ContextSingleton.RefreshContext(); }