Example #1
0
        public void UpdateSettings(DTO.Settings updatedSettings)
        {
            CheckHelper.ArgumentNotNull(updatedSettings, "updatedSettings");
            CheckHelper.ArgumentWithinCondition(!updatedSettings.IsNew(), "!updatedSettings.IsNew()");
            Container.Get <IValidateService>().CheckIsValid(updatedSettings);

            CheckHelper.WithinCondition(SecurityService.IsLoggedIn, "User is not logged in.");
            CheckHelper.WithinCondition(SecurityService.IsCurrentUserAdministrator, "Only administrator can update settings.");

            var persistentService = Container.Get <IPersistentService>();

            var settings =
                Container
                .Get <IPersistentService>()
                .GetEntitySet <DataAccess.Settings>()
                .SingleOrDefault();

            CheckHelper.ArgumentNotNull(settings, "Cannot find settings.");
            CheckHelper.WithinCondition(settings.Id == updatedSettings.Id, "settings.Id == updatedSettings.Id");

            settings.RublesPerDollar = updatedSettings.RublesPerDollar;

            settings.UpdateTrackFields(Container);

            persistentService.SaveChanges();

            _settings = null;
        }
Example #2
0
        public DTO.Settings CreateSettings(DataAccess.Settings settings)
        {
            CheckHelper.ArgumentNotNull(settings, "settings");
            CheckHelper.ArgumentWithinCondition(!settings.IsNew(), "!settings.IsNew()");

            return
                (_dtoCache.Get(
                     settings,
                     s =>
            {
                var result =
                    new DTO.Settings
                {
                    Id = s.Id,
                    RublesPerDollar = s.RublesPerDollar
                };

                CopyTrackableFields(result, s);

                return result;
            }));
        }
Example #3
0
        public void UpdateSettings_Should_Throw_Exception_When_Current_User_Is_Not_Administrator()
        {
            // Arrange
            var container = ContainerMockFactory.Create();

            container.Get <ISecurityService>().LogIn(UserMockFactory.Olesya.Login, EncryptServiceMockFactory.OlesyaPasswordData.Password);

            var updatedSettings =
                new DTO.Settings
            {
                Id = SettingsMockFactory.SingleSettings.Id,
                RublesPerDollar = 34
            };

            var settingsService = container.Get <ISettingsService>();

            // Act
            // Assert
            ExceptionAssert.Throw <InvalidOperationException>(
                () => settingsService.UpdateSettings(updatedSettings),
                "Only administrator can update settings.");
        }
Example #4
0
        public void UpdateSettings_Should_Update_Settings()
        {
            // Arrange
            var container = ContainerMockFactory.Create();

            container.Get <ISecurityService>().LogIn(UserMockFactory.Jenya.Login, EncryptServiceMockFactory.JenyaPasswordData.Password);

            const decimal NEW_SETTINGS_RUBLES_PER_DOLLAR = 34;
            var           createDate = SettingsMockFactory.SingleSettings.CreateDate;
            var           createdBy  = SettingsMockFactory.SingleSettings.CreatedBy;

            var updatedSettings =
                new DTO.Settings
            {
                Id = SettingsMockFactory.SingleSettings.Id,
                RublesPerDollar = NEW_SETTINGS_RUBLES_PER_DOLLAR
            };

            var settingsService   = container.Get <ISettingsService>();
            var persistentService = container.Get <IPersistentService>();
            var timeService       = container.Get <ITimeService>();

            // Act
            settingsService.UpdateSettings(updatedSettings);

            // Assert
            var actualSettings = persistentService.GetEntitySet <DataAccess.Settings>().Single();

            Assert.AreEqual(SettingsMockFactory.SingleSettings.Id, actualSettings.Id);
            Assert.AreEqual(NEW_SETTINGS_RUBLES_PER_DOLLAR, actualSettings.RublesPerDollar);
            Assert.AreEqual(createDate, actualSettings.CreateDate);
            Assert.AreEqual(timeService.UtcNow, actualSettings.ChangeDate);
            Assert.AreEqual(createdBy, actualSettings.CreatedBy);
            Assert.AreEqual(UserMockFactory.Jenya, actualSettings.ChangedBy);

            Assert.AreEqual(updatedSettings, container.Get <IDtoService>().CreateSettings(actualSettings));
        }