public void UpdateSize_Should_Throw_Exception_When_Size_With_The_Same_Name_Brand_SubCategory_Already_Exists() { var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); var updatedSize = new DTO.Size { Id = SizeMockFactory.Carters_Boys_0_2_3M.Id, Name = SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.Name, Brand = container.Get <IDtoService>().CreateBrand(SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.Brand), SubCategory = container.Get <IDtoService>().CreateSubCategory(SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months.SubCategory), Weight = "New Weight", Height = "New Height", Active = true }; var sizeService = container.Get <ISizeService>(); // Act // Assert ExceptionAssert.Throw <SizeServiceException>( () => sizeService.UpdateSize(updatedSize), "Размер с заданным названием уже существует для данной подкатегории и данного бренда."); }
public void UpdateProductSize_Should_Throw_Exception_When_Current_User_Is_Not_Seller() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); var size = container.Get <IDtoService>().CreateSize(SizeMockFactory.TheChildrensPlace_Boys_0_2_Newborn); var product = container.Get <IDtoService>().CreateProduct(ProductMockFactory.TheChildrensPlace_Boys_TShirt); const decimal NEW_PRODUCT_SIZE_PRICE = 1200; var updatedProductSize = new DTO.ProductSize { Id = ProductSizeMockFactory.Boys_Sweater_0_3_Months.Id, Size = size, Product = product, Active = false, Price = NEW_PRODUCT_SIZE_PRICE }; var productSizeService = container.Get <IProductSizeService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => productSizeService.UpdateProductSize(updatedProductSize), "Only seller can change product size."); }
public void UpdateProductSize_Should_Throw_Exception_When_ProductSize_With_The_Same_Product_Size_Already_Exists() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); var size = container.Get <IDtoService>().CreateSize(SizeMockFactory.TheChildrensPlace_Boys_0_2_0_3_Months); var product = container.Get <IDtoService>().CreateProduct(ProductMockFactory.TheChildrensPlace_Boys_Sweater); const decimal NEW_PRODUCT_SIZE_PRICE = 1200; var updatedProductSize = new DTO.ProductSize { Id = ProductSizeMockFactory.Girls_Sweater_0_3_Months.Id, Size = size, Product = product, Active = true, Price = NEW_PRODUCT_SIZE_PRICE }; var productSizeService = container.Get <IProductSizeService>(); // Act // Assert ExceptionAssert.Throw <ProductSizeServiceException>( () => productSizeService.UpdateProductSize(updatedProductSize), "Размер товара с заданным размером уже существует для данного товара."); }
public void UpdateParcel_Should_Throw_Exception_When_Current_User_Is_Distributor_And_Parcel_Is_Assigned_To_Another_Distributor() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); UserRoleMockFactory.OlesyaDistributor.Active = true; UserRoleMockFactory.OlesyaPurchaser.Active = false; UserRoleMockFactory.OlesyaAdministrator.Active = false; UserRoleMockFactory.OlesyaSeller.Active = false; securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); var updatedParcel = new DTO.Parcel { Id = ParcelMockFactory.Parcel_2.Id, RublesPerDollar = 31.5m, PurchaserSpentOnDelivery = 149m, TrackingNumber = "US867958674896Z", SentDate = new DateTime(2013, 5, 31), Distributor = container.Get <IDtoService>().CreateUser(UserMockFactory.Diana), Comments = "Some comments", ReceivedDate = new DateTime(2013, 6, 30) }; var parcelService = container.Get <IParcelService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => parcelService.UpdateParcel(updatedParcel), "Only purchaser and distributor can change parcel."); }
public void UpdateUser_Should_Throw_Exception_When_User_Tries_Remove_Administrator_Role() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Jenya.Login, EncryptServiceMockFactory.JenyaPasswordData.Password); var dtoService = container.Get <IDtoService>(); var updatedUser = new DTO.User { Id = UserMockFactory.Jenya.Id, Email = "*****@*****.**", FirstName = "New First Name", LastName = "New Last Name", Login = "******", Active = true, Roles = new[] { dtoService.CreateRole(RoleMockFactory.Purchaser), dtoService.CreateRole(RoleMockFactory.Distributor) } }; // Act // Assert ExceptionAssert.Throw <SecurityServiceException>( () => securityService.UpdateUser(updatedUser), "Пользователь не может удалить роль администратора у себя."); }
public void UpdateUser_Should_Throw_Exception_When_User_With_The_Same_Login_Already_Exists() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Jenya.Login, EncryptServiceMockFactory.JenyaPasswordData.Password); var dtoService = container.Get <IDtoService>(); var updatedUser = new DTO.User { Id = UserMockFactory.Jenya.Id, Email = "*****@*****.**", FirstName = "New First Name", LastName = "New Last Name", Login = UserMockFactory.Olesya.Login, Active = true, Roles = new[] { dtoService.CreateRole(RoleMockFactory.Administrator), dtoService.CreateRole(RoleMockFactory.Purchaser), dtoService.CreateRole(RoleMockFactory.Distributor) } }; // Act // Assert ExceptionAssert.Throw <SecurityServiceException>( () => securityService.UpdateUser(updatedUser), "Пользователь с заданным логином уже существует."); }
public void CreateParcel_Should_Throw_Exception_When_Current_User_Is_Not_Purchaser() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); var createdParcel = new DTO.Parcel { RublesPerDollar = 31.5m, PurchaserSpentOnDelivery = 149m, TrackingNumber = "US867958674896Z", SentDate = new DateTime(2013, 5, 31), Distributor = container.Get <IDtoService>().CreateUser(UserMockFactory.Olesya), Comments = "Some comments" }; var parcelService = container.Get <IParcelService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => parcelService.CreateParcel(createdParcel), "Only purchaser can create parcel."); }
public void UpdateDistributorTransfer_Should_Throw_Exception_When_Transfer_Is_Created_By_Another_Distributor() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); UserRoleMockFactory.OlesyaDistributor.Active = true; UserRoleMockFactory.OlesyaPurchaser.Active = false; UserRoleMockFactory.OlesyaAdministrator.Active = false; UserRoleMockFactory.OlesyaSeller.Active = false; securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); var updatedDistributorTransfer = new DTO.DistributorTransfer { Id = DistributorTransferMockFactory.Diana_Transfer_1.Id, Date = new DateTime(2013, 7, 23), Amount = 10200m, Active = false, RublesPerDollar = 33.1m }; var distributorTransferService = container.Get <IDistributorTransferService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => distributorTransferService.UpdateDistributorTransfer(updatedDistributorTransfer), "Distributor can only change distributor transfer created by him."); }
public void UpdateSubCategory_Should_Throw_Exception_When_Current_User_Is_Not_Seller() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); var updatedSubCategory = new DTO.SubCategory { Id = SubCategoryMockFactory.Girls_5_12.Id, Name = "New SubCategory", Category = container.Get <IDtoService>().CreateCategory(CategoryMockFactory.Men), Active = true }; var categoryService = container.Get <ICategoryService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => categoryService.UpdateSubCategory(updatedSubCategory), "Only seller can change subcategory."); }
public void ResetPassword_Should_Throw_Exception_When_Current_User_Is_Not_Administrator() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); var dtoService = container.Get <IDtoService>(); var changedUser = dtoService.CreateUser(UserMockFactory.Olesya); container.Remove <IPasswordGeneratorService>(); var passwordGeneratorServiceMock = new Mock <IPasswordGeneratorService>(); passwordGeneratorServiceMock .Setup(m => m.GenerateTemporaryPassword(changedUser.Login)) .Returns(EncryptServiceMockFactory.NewPasswordData.Password); container.SetConstant <IPasswordGeneratorService, IPasswordGeneratorService>(passwordGeneratorServiceMock.Object); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => securityService.ResetPassword(changedUser), "Only administrator can reset password."); }
public void ResetPassword_Should_Throw_Exception_When_User_Is_Inactive() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Jenya.Login, EncryptServiceMockFactory.JenyaPasswordData.Password); var dtoService = container.Get <IDtoService>(); var changedUser = dtoService.CreateUser(UserMockFactory.Andrey); container.Remove <IPasswordGeneratorService>(); var passwordGeneratorServiceMock = new Mock <IPasswordGeneratorService>(); passwordGeneratorServiceMock .Setup(m => m.GenerateTemporaryPassword(changedUser.Login)) .Returns(EncryptServiceMockFactory.NewPasswordData.Password); container.SetConstant <IPasswordGeneratorService, IPasswordGeneratorService>(passwordGeneratorServiceMock.Object); // Act // Assert ExceptionAssert.Throw <SecurityServiceException>( () => securityService.ResetPassword(changedUser), "Пользователь отключен администратором."); }
public void UpdateSize_Should_Throw_Exception_When_Current_User_Is_Not_Seller() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); var updatedSize = new DTO.Size { Id = SizeMockFactory.Carters_Boys_0_2_3M.Id, Name = "New Size", SubCategory = container.Get <IDtoService>().CreateSubCategory(SubCategoryMockFactory.Girls_0_2), Brand = container.Get <IDtoService>().CreateBrand(BrandMockFactory.Crazy8), Weight = "New Weight", Height = "New Height", Active = true }; var sizeService = container.Get <ISizeService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => sizeService.UpdateSize(updatedSize), "Only seller can change size."); }
public void ResetPassword_Should_Throw_Exception_When_CurrentUser_Tries_To_Reset_Password_To_Himself() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Jenya.Login, EncryptServiceMockFactory.JenyaPasswordData.Password); var dtoService = container.Get <IDtoService>(); var changedUser = dtoService.CreateUser(UserMockFactory.Jenya); container.Remove <IPasswordGeneratorService>(); var passwordGeneratorServiceMock = new Mock <IPasswordGeneratorService>(); passwordGeneratorServiceMock .Setup(m => m.GenerateTemporaryPassword(changedUser.Login)) .Returns(EncryptServiceMockFactory.NewPasswordData.Password); container.SetConstant <IPasswordGeneratorService, IPasswordGeneratorService>(passwordGeneratorServiceMock.Object); // Act // Assert ExceptionAssert.Throw <SecurityServiceException>( () => securityService.ResetPassword(changedUser), "Пользователь не может сбросить себе пароль."); }
public void AddByCodeOnlyTest() { // code already exists { string name = "The name"; var target = new CategoricalVariable(name) { 2.0 }; ExceptionAssert.Throw( () => { target.Add(2.0); }, expectedType: typeof(InvalidOperationException), expectedMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_CAT_ALREADY_EXISTS_IN_VARIABLE_LIST")); } // target is read only { string name = "The name"; var target = new CategoricalVariable(name); target.SetAsReadOnly(); ExceptionAssert.Throw( () => { target.Add(3.0); }, expectedType: typeof(InvalidOperationException), expectedMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_CAT_VARIABLE_IS_READONLY")); } // Valid input { string name = "The name"; var target = new CategoricalVariable(name); double code; Category category0, category1; code = 1.0; target.Add(code); category0 = new Category(code); code = 2.0; target.Add(code); category1 = new Category(code); CategoricalVariableAssert.IsStateAsExpected( target, name, expectedCategories: new List <Category>(2) { category0, category1 }, expectedReadOnlyFlag: false); } }
public void Test_IsValid_Should_Throw_Exception_When_Value_Is_Not_String() { // Arrange var attr = new StringValidateAttribute("Test message"); // Act // Assert ExceptionAssert.Throw <InvalidCastException>( () => attr.IsValid(5)); }
public void Settings_Should_Throw_Exception_When_Current_User_Is_Not_Logged_In() { // Arrange var container = ContainerMockFactory.Create(); var settingsService = container.Get <ISettingsService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => { var settings = settingsService.Settings; }, "User is not logged in."); }
public void LogIn_Should_Throw_Exception_When_User_Is_Inactive() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); // Act // Assert ExceptionAssert.Throw <SecurityServiceException>( () => securityService.LogIn(UserMockFactory.Andrey.Login, EncryptServiceMockFactory.AndreyPasswordData.Password), "Пользователь с заданным логином отключен администратором."); }
public void LogIn_Should_Throw_Exception_When_Wrong_Password() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); // Act // Assert ExceptionAssert.Throw <SecurityServiceException>( () => securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.WrongPasswordData.Password), "Пользователь с заданным логином и паролем не существует."); }
public void GetActionLogs_Should_Throw_Exception_When_User_Is_Not_Logged_In() { // Arrange var container = ContainerMockFactory.Create(); var actionLogService = container.Get <IActionLogService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => actionLogService.GetActionLogs(TimeServiceMockFactory.Date2, TimeServiceMockFactory.Date5, null), "User is not logged in."); }
public void LogIn_Should_Throw_Exception_When_Log_In_Twice() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password), "User is already logged in."); }
public void GetUsers_Should_Throw_Exception_When_Current_User_Is_Not_Administrator_And_Not_Purchaser() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => securityService.GetUsers(null), "Only administrator and purchaser can get all users."); }
public void UpdateUser_Should_Throw_Exception_When_Current_User_Is_Not_Administrator() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => securityService.UpdateUser(securityService.CurrentUser), "Only administrator can change user data."); }
public void ChangePassword_Should_Throw_Exception_When_Guest_Attempts_Change_Password() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogInGuest(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => securityService.ChangePassword(EncryptServiceMockFactory.NewPasswordData.Password), "Guest cannot change password."); }
public void GetActionLogs_Should_Throw_Exception_When_User_Is_Not_Administrator() { // Arrange var container = ContainerMockFactory.Create(); container.Get <ISecurityService>().LogIn(UserMockFactory.Diana.Login, EncryptServiceMockFactory.DianaPasswordData.Password); var actionLogService = container.Get <IActionLogService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => actionLogService.GetActionLogs(TimeServiceMockFactory.Date2, TimeServiceMockFactory.Date5, null), "User is not administrator."); }
public void GetSizes_Should_Throw_Exception_When_Current_User_Is_Not_Seller() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); securityService.LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password); var sizeService = container.Get <ISizeService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => sizeService.GetSizes(null), "Only seller can get all sizes."); }
public void GetActiveProductsByBrand_Should_Throw_Exception_When_User_Is_Not_Logged_In() { // Arrange var container = ContainerMockFactory.Create(); var dtoService = container.Get <IDtoService>(); var productService = container.Get <IProductService>(); var brand = dtoService.CreateBrand(BrandMockFactory.TheChildrensPlace); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => productService.GetActiveProductsByBrand(brand), "User is not logged in."); }
public void GetActiveProductsBySubCategory_Should_Throw_Exception_When_User_Is_Not_Logged_In() { // Arrange var container = ContainerMockFactory.Create(); var dtoService = container.Get <IDtoService>(); var productService = container.Get <IProductService>(); var subCategory = dtoService.CreateSubCategory(SubCategoryMockFactory.Boys_0_2); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => productService.GetActiveProductsBySubCategory(subCategory), "User is not logged in."); }
public void GetParcels_Should_Throw_Exception_When_Current_User_Is_Not_Seller_Purchaser_Distributor() { // Arrange var container = ContainerMockFactory.Create(); var securityService = container.Get <ISecurityService>(); UserMockFactory.Andrey.Active = true; securityService.LogIn(UserMockFactory.Andrey.Login, EncryptServiceMockFactory.AndreyPasswordData.Password); var parcelService = container.Get <IParcelService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => parcelService.GetParcels(TimeServiceMockFactory.Date1, TimeServiceMockFactory.Date5, null), "Only seller, purchaser and distributor can get all parcels."); }
public void DeserializationUnexpectedEntryTypeTest() { ExceptionAssert.Throw( () => { CsvComplexMatrixSerializer.Deserialize( Path.Combine("Data", "deserialize-valid-expected-complex-declared-double.csv")); }, expectedType: typeof(InvalidOperationException), expectedMessage: ImplementationServices.GetResourceString( "STR_EXCEPT_REP_UNABLE_TO_DESERIALIZE"), expectedInnerType: typeof(InvalidOperationException), expectedInnerMessage: String.Format( ImplementationServices.GetResourceString( "STR_EXCEPT_REP_DESERIALIZE_UNEXPECTED_ENTRY_TYPE"), "Double", "Complex")); }
public void GetActiveSizes_Should_Throw_Exception_When_User_Is_Not_Logged_In() { // Arrange var container = ContainerMockFactory.Create(); var dtoService = container.Get <IDtoService>(); var subCategory = dtoService.CreateSubCategory(SubCategoryMockFactory.Boys_0_2); var brand = dtoService.CreateBrand(BrandMockFactory.Carters); var sizeService = container.Get <ISizeService>(); // Act // Assert ExceptionAssert.Throw <InvalidOperationException>( () => sizeService.GetActiveSizes(subCategory, brand), "User is not logged in."); }