public void ShouldDeleteProfile() { var profile = new Profile { Id = Guid.NewGuid(), Login = "******", Avatar = Guid.NewGuid(), Password = "******", Name = "odmin", Surname = "odmin" }; var repository = new ProfilesRepository(Constants.Constants.ConnectionString); repository.CreateProfile(profile); repository.DeleteProfile(profile.Id); try { repository.GetProfile(profile.Id); } catch (Exception) { } }
public void ShouldGetProfileById() { var profile = new Profile { Id = Guid.NewGuid(), Login = "******", Avatar = Guid.NewGuid(), Password = "******", Name = "odmin", Surname = "odmin" }; var repository = new ProfilesRepository(Constants.Constants.ConnectionString); repository.CreateProfile(profile); _tempUsers.Add(profile.Id); var result = repository.GetProfile(profile.Id); Assert.AreEqual(profile.Login, result.Login); Assert.AreEqual(profile.Name, result.Name); Assert.AreEqual(profile.Surname, result.Surname); }
/// <summary> /// Update dimension value, it will check dimension type for /// </summary> /// <param name="idProduct">ID Product</param> /// <param name="idClient">ID Client (external code)</param> /// <param name="idProfile">ID Profile</param> /// <param name="idDimension">ID Dimension (must to be consumible)</param> /// <param name="value">New value for dimension</param> /// <returns></returns> public ActionResponse UpdateValueDimensionAction(int idProduct, int idClient, int idProfile, int idDimension, decimal value) { try { // Check if product exists var oProduct = this.productsRepository.GetProduct(idProduct); if (oProduct == null) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No existe el producto", null)); } // Check if client (user) exists or it's linked to product var oUser = this.usersRepository.GetUserv2(idClient.ToString(), idProduct); if (oUser == null) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "El usuario no existe o no está relacionado con el producto", null)); } if (!oUser.Active.Value) { return(utilities.Response((int)CodeStatusEnum.CONFLICT, "El usuario indicado no se encuentra activo en la plataforma", null)); } int idUser = oUser.IdUser; // ID USER FREEMIUM // Check if profile exists var oProfile = profilesRepository.GetProfile(idProfile); if (oProfile == null) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "El perfil no existe en el sistema", null)); } // Check if product has profiles associated and idProfile is part of it var profiles = oProduct.Profiles; if (profiles.Count <= 0) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "El producto no posee perfiles configurados", null)); } bool isValidProfile = false; foreach (var oProf in profiles) { if (oProf.IdProfile == idProfile) { isValidProfile = true; break; } } if (!isValidProfile) { return(utilities.Response((int)CodeStatusEnum.CONFLICT, "El perfil no tiene relación con el producto", null)); } // Check if dimension exists var oDimension = this.dimensionsRepository.GetDimension(idDimension); if (oDimension == null) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No existe ninguna dimensión con el identificador proporcionado", null)); } // Check dimension is related to profile across dimensioncategories var dimensionCategories = oProduct.DimensionsCategories; if (dimensionCategories.Count <= 0) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No existen categorías de dimensión asociadas al producto", null)); } bool okDimension = false; foreach (var oDimensionCategory in dimensionCategories) { // Will find dimension if (oDimensionCategory.IdDimensionCategory == oDimension.IdDimensionCategory) { okDimension = true; break; } } if (!okDimension) { return(utilities.Response((int)CodeStatusEnum.CONFLICT, "La dimensión no está relacionada a ninguna categoría", null)); } // Update value dimension // If dimension is consumible will update it if (oDimension.IdDimensionType == (int)DimensionTypeEnum.CONSUMIBLE) { // Find subscription var subscription = subscriptionsRepository.GetUserCurrentSubscription(idUser); if (subscription == null) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No se pudo determinar la subscripción del usuario", null)); } // Update value var userDimension = usersDimensionsRepository.GetUserDimension(idDimension, subscription.IdSubscription); if (userDimension == null) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No se pudo determinar la dimensión del usuario", null)); } if (userDimension.CurrentValue == null) { return(utilities.Response((int)CodeStatusEnum.NO_CONTENT, "No se pudo determinar el valor de la dimensión del usuario", null)); } decimal oldValueX = userDimension.CurrentValue.Value; bool action = usersDimensionsRepository.UpdateUserDimensionValue(userDimension.IdUserDimension, value); DimensionTypeEnum dimensionTypeEnum = (DimensionTypeEnum)oDimension.IdDimensionType.Value; UpdateValueDimensionResponse response = new UpdateValueDimensionResponse { idDimension = idDimension, nameDimension = oDimension.Description, tagName = oDimension.TagName, idDimensionType = oDimension.IdDimensionType.Value, nameDimensionType = dimensionTypeEnum.ToString(), oldValue = oldValueX, currentValue = value }; return(utilities.Response((int)CodeStatusEnum.OK, "OK", response)); } else { return(utilities.Response((int)CodeStatusEnum.CONFLICT, "La dimensión no es del tipo consumible", null)); } } catch (Exception e) { return(utilities.Response((int)CodeStatusEnum.INTERNAL_ERROR, "Error desconocido en el sistema: " + e.Message, null)); } }