Example #1
0
 public FinanceOperationsImpl(
     IUnitOfWork unitOfWork,
     IEmailService emailService,
     IFieldDefaultValueGenerator fieldDefaultValueGenerator,
     IVirtualUsersService vpu,
     ICurrentUserAccessor currentUserAccessor
     ) : base(unitOfWork, emailService, fieldDefaultValueGenerator, currentUserAccessor) => _vpu = vpu;
Example #2
0
        public void SaveOnAddTest()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock  = new MockedProject();
            var claim = mock.CreateClaim(mock.Character, mock.Player);

            // ReSharper disable once MustUseReturnValue
            FieldSaveHelper.SaveCharacterFields(
                mock.Player.UserId,
                claim,
                new Dictionary <int, string>()
            {
                { mock.CharacterField.ProjectFieldId, "test" },
            },
                _generator);
            mock.Character.JsonData
            .ShouldBe(_original.Character.JsonData,
                      "Adding claim should not modify any character fields");

            mock.Character.Groups.Select(g => g.CharacterGroupId).ShouldBe(
                mock.Character.Groups.Select(g => g.CharacterGroupId),
                "Adding claim should not modify any character groups");

            claim.JsonData.ShouldBe($"{{\"{mock.CharacterField.ProjectFieldId}\":\"test\"}}");
        }
Example #3
0
 protected ClaimImplBase(IUnitOfWork unitOfWork, IEmailService emailService,
                         IFieldDefaultValueGenerator fieldDefaultValueGenerator,
                         ICurrentUserAccessor currentUserAccessor) : base(unitOfWork, currentUserAccessor)
 {
     EmailService = emailService;
     FieldDefaultValueGenerator = fieldDefaultValueGenerator;
 }
 public ProjectService(IUnitOfWork unitOfWork,
                       IEmailService emailService,
                       IFieldDefaultValueGenerator fieldDefaultValueGenerator) : base(unitOfWork)
 {
     FieldDefaultValueGenerator = fieldDefaultValueGenerator;
     EmailService = emailService;
 }
 public FinanceOperationsImpl(IUnitOfWork unitOfWork,
                              IEmailService emailService,
                              IFieldDefaultValueGenerator fieldDefaultValueGenerator) : base(unitOfWork,
                                                                                             emailService,
                                                                                             fieldDefaultValueGenerator)
 {
 }
Example #6
0
        public void DisableUnapprovedClaimToChangeCharacterTest()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock  = new MockedProject();
            var claim = mock.CreateClaim(mock.Character, mock.Player);

            FieldSaveHelper.SaveCharacterFields(
                mock.Player.UserId,
                claim,
                new Dictionary <int, string>()
            {
                { mock.CharacterField.ProjectFieldId, "test" },
            },
                _generator);
            ShouldBeTestExtensions.ShouldBe(mock.Character.JsonData,
                                            _original.Character.JsonData,
                                            "Adding claim should not modify any character fields");
            mock.Character.Groups.Select(g => g.CharacterGroupId).ToList().ShouldBe(
                (IEnumerable <int>)_original.Character.Groups.Select(g => g.CharacterGroupId)
                .ToList(),
                "Adding claim should not modify any character groups");
            ShouldBeTestExtensions.ShouldBe(claim.JsonData,
                                            $"{{\"{mock.CharacterField.ProjectFieldId}\":\"test\"}}");
        }
Example #7
0
        private static IReadOnlyCollection <FieldWithPreviousAndNewValue> SaveCharacterFieldsImpl(
            int currentUserId,
            [CanBeNull]
            Character character,
            [CanBeNull]
            Claim claim,
            [NotNull]
            IReadOnlyDictionary <int, string> newFieldValue,
            IFieldDefaultValueGenerator generator)
        {
            if (newFieldValue == null)
            {
                throw new ArgumentNullException(nameof(newFieldValue));
            }

            var strategy = CreateStrategy(currentUserId, character, claim, generator);

            var fields = strategy.LoadFields();

            AssignValues(newFieldValue, fields, strategy);

            GenerateDefaultValues(character, fields, strategy);

            strategy.Save(fields);
            return(strategy.GetUpdatedFields());
        }
Example #8
0
 public ClaimServiceImpl(IUnitOfWork unitOfWork, IEmailService emailService,
                         IFieldDefaultValueGenerator fieldDefaultValueGenerator,
                         IAccommodationInviteService accommodationInviteService) : base(unitOfWork, emailService,
                                                                                        fieldDefaultValueGenerator)
 {
     this._accommodationInviteService = accommodationInviteService;
 }
Example #9
0
        private static IReadOnlyCollection <FieldWithPreviousAndNewValue> SaveCharacterFieldsImpl(
            int currentUserId,
            [CanBeNull]
            Character character,
            [CanBeNull]
            Claim claim,
            [NotNull]
            IReadOnlyDictionary <int, string> newFieldValue,
            IFieldDefaultValueGenerator generator)
        {
            if (newFieldValue == null)
            {
                throw new ArgumentNullException(nameof(newFieldValue));
            }

            FieldSaveStrategyBase strategy;

            if (claim == null)
            {
                strategy =
                    new SaveToCharacterOnlyStrategy(null, character, currentUserId, generator);
            }
            else if (!claim.IsApproved)
            {
                strategy = new SaveToClaimOnlyStrategy(claim, null, currentUserId, generator);
            }
            else
            {
                strategy =
                    new SaveToCharacterAndClaimStrategy(claim, character, currentUserId, generator);
            }

            var fields = strategy.LoadFields();

            foreach (var keyValuePair in newFieldValue)
            {
                var field = fields[keyValuePair.Key];

                strategy.EnsureEditAccess(field);

                var normalizedValue = NormalizeValueBeforeAssign(field, keyValuePair.Value);

                strategy.AssignFieldValue(field, normalizedValue);
            }

            foreach (var field in fields.Values.Where(
                         f => !f.HasEditableValue && f.Field.CanHaveValue() &&
                         f.Field.IsAvailableForTarget(character)))
            {
                var newValue = strategy.GenerateDefaultValue(field);

                var normalizedValue = NormalizeValueBeforeAssign(field, newValue);

                strategy.AssignFieldValue(field, normalizedValue);
            }

            strategy.Save(fields);
            return(strategy.GetUpdatedFields());
        }
 public CharacterServiceImpl(
     IUnitOfWork unitOfWork,
     IEmailService emailService,
     IFieldDefaultValueGenerator fieldDefaultValueGenerator) : base(unitOfWork)
 {
     EmailService = emailService;
     FieldDefaultValueGenerator = fieldDefaultValueGenerator;
 }
Example #11
0
            protected new Claim Claim => base.Claim !; //Claim should always exists

            public SaveToClaimOnlyStrategy(Claim claim,
                                           int currentUserId,
                                           IFieldDefaultValueGenerator generator) : base(claim,
                                                                                         character: null,
                                                                                         currentUserId,
                                                                                         generator)
            {
            }
Example #12
0
 public SaveToCharacterAndClaimStrategy(Claim claim,
                                        Character character,
                                        int currentUserId,
                                        IFieldDefaultValueGenerator generator) : base(claim,
                                                                                      character,
                                                                                      currentUserId,
                                                                                      generator)
 {
 }
Example #13
0
 public FinanceOperationsImpl(
     IUnitOfWork unitOfWork,
     IEmailService emailService,
     IFieldDefaultValueGenerator fieldDefaultValueGenerator,
     IVirtualUsersService vpu
     ) : base(unitOfWork, emailService, fieldDefaultValueGenerator)
 {
     _vpu = vpu;
 }
 public CharacterServiceImpl(
     IUnitOfWork unitOfWork,
     IEmailService emailService,
     IFieldDefaultValueGenerator fieldDefaultValueGenerator,
     ICurrentUserAccessor currentUserAccessor
     ) : base(unitOfWork, currentUserAccessor)
 {
     EmailService = emailService;
     FieldDefaultValueGenerator = fieldDefaultValueGenerator;
 }
Example #15
0
 protected FieldSaveStrategyBase(Claim?claim,
                                 Character?character,
                                 int currentUserId,
                                 IFieldDefaultValueGenerator generator)
 {
     Claim         = claim;
     Character     = character;
     CurrentUserId = currentUserId;
     Generator     = generator;
     Project       = character?.Project ?? claim?.Project ?? throw new ArgumentNullException("",
                                                                                             "Either character or claim should be not null");
 }
Example #16
0
 public static IReadOnlyCollection <FieldWithPreviousAndNewValue> SaveCharacterFields(
     int currentUserId,
     [NotNull] Character character,
     [NotNull] IDictionary <int, string> newFieldValue,
     IFieldDefaultValueGenerator generator)
 {
     if (character == null)
     {
         throw new ArgumentNullException(nameof(character));
     }
     return(SaveCharacterFieldsImpl(currentUserId, character, character.ApprovedClaim, newFieldValue, generator));
 }
Example #17
0
        public void TryToChangeAnotherUserCharacter()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock = new MockedProject();

            _ = Should.Throw <NoAccessToProjectException>(() =>
                                                          FieldSaveHelper.SaveCharacterFields(
                                                              mock.Player.UserId,
                                                              mock.Character,
                                                              new Dictionary <int, string?>()
            {
                { mock.CharacterField.ProjectFieldId, "test" },
            },
                                                              _generator));
        }
Example #18
0
        public void TryToChangeMasterOnlyFieldOnAdd()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock = new MockedProject();

            Should.Throw <NoAccessToProjectException>(() =>
                                                      FieldSaveHelper.SaveCharacterFields(
                                                          mock.Player.UserId,
                                                          mock.CreateClaim(mock.Character, mock.Player),
                                                          new Dictionary <int, string>()
            {
                { mock.MasterOnlyField.ProjectFieldId, "test" },
            },
                                                          _generator));
        }
Example #19
0
        public void HiddenFieldChangeFailedTest()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock  = new MockedProject();
            var claim = mock.CreateClaim(mock.Group, mock.Player);

            Should.Throw <NoAccessToProjectException>(() =>
                                                      FieldSaveHelper.SaveCharacterFields(
                                                          mock.Player.UserId,
                                                          claim,
                                                          new Dictionary <int, string>()
            {
                { mock.HideForUnApprovedClaim.ProjectFieldId, "test" },
            },
                                                          _generator));
        }
Example #20
0
        public void MasterHiddenChangeTest()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock        = new MockedProject();
            var publicField = new FieldWithValue(mock.PublicField, "Public");

            MockedProject.AssignFieldValues(mock.Character, publicField);
            FieldSaveHelper.SaveCharacterFields(
                mock.Master.UserId,
                mock.Character,
                new Dictionary <int, string>()
            {
                { mock.HideForUnApprovedClaim.ProjectFieldId, "test" },
                { mock.CharacterField.ProjectFieldId, null },
            },
                _generator);

            mock.Character.FieldValuesShouldBe(new FieldWithValue(mock.HideForUnApprovedClaim, "test"), publicField);
        }
Example #21
0
        public void ApprovedClaimChangeTest()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock  = new MockedProject();
            var claim = mock.CreateApprovedClaim(mock.Character, mock.Player);

            FieldSaveHelper.SaveCharacterFields(
                mock.Player.UserId,
                claim,
                new Dictionary <int, string>()
            {
                { mock.CharacterField.ProjectFieldId, "test" },
            },
                _generator);

            mock.Character.FieldValuesShouldBe(new FieldWithValue(mock.CharacterField, "test"));

            ShouldBeTestExtensions.ShouldBe(claim.JsonData, "{}");
        }
Example #22
0
        private static FieldSaveStrategyBase CreateStrategy(int currentUserId, Character character,
                                                            Claim claim, IFieldDefaultValueGenerator generator)
        {
            FieldSaveStrategyBase strategy;

            if (claim == null)
            {
                strategy =
                    new SaveToCharacterOnlyStrategy(null, character, currentUserId, generator);
            }
            else if (!claim.IsApproved)
            {
                strategy = new SaveToClaimOnlyStrategy(claim, null, currentUserId, generator);
            }
            else
            {
                strategy =
                    new SaveToCharacterAndClaimStrategy(claim, character, currentUserId, generator);
            }

            return(strategy);
        }
        public void TryToSkipMandatoryField()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock = new MockedProject();

            mock.CharacterField.MandatoryStatus = MandatoryStatus.Required;

            var claim = mock.CreateApprovedClaim(mock.Character, mock.Player);

            var exception = Should.Throw <FieldRequiredException>(() =>
                                                                  FieldSaveHelper.SaveCharacterFields(
                                                                      mock.Player.UserId,
                                                                      claim,
                                                                      new Dictionary <int, string>()
            {
                { mock.CharacterField.ProjectFieldId, "" },
            },
                                                                      _generator));

            exception.FieldName.ShouldBe(mock.CharacterField.FieldName);
        }
        public void SkipOptionalField()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock = new MockedProject();

            mock.CharacterField.MandatoryStatus = MandatoryStatus.Optional;

            var claim = mock.CreateApprovedClaim(mock.Character, mock.Player);

            var exception = Should.NotThrow(() =>
                                            FieldSaveHelper.SaveCharacterFields(
                                                mock.Player.UserId,
                                                claim,
                                                new Dictionary <int, string>()
            {
                { mock.CharacterField.ProjectFieldId, "" },
            },
                                                _generator));

            mock.Character.JsonData.ShouldBe("{}");
        }
Example #25
0
        public void ConditionalFieldChangeTestForGroup()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock             = new MockedProject();
            var claim            = mock.CreateClaim(mock.Group, mock.Player);
            var conditionalField = mock.CreateConditionalField();

            FieldSaveHelper.SaveCharacterFields(
                mock.Player.UserId,
                claim,
                new Dictionary <int, string>()
            {
                { conditionalField.ProjectFieldId, "test" },
            },
                _generator);
            ShouldBeTestExtensions.ShouldBe(claim.JsonData,
                                            $"{{\"{conditionalField.ProjectFieldId}\":\"test\"}}");
            ShouldBeTestExtensions.ShouldBe(mock.Character.JsonData,
                                            _original.Character.JsonData,
                                            "Adding claim should not modify any character fields");
        }
Example #26
0
        public void ApprovedClaimHiddenChangeTest()
        {
            _original  = new MockedProject();
            _generator = new MockedFieldDefaultValueGenerator();
            var mock  = new MockedProject();
            var claim = mock.CreateApprovedClaim(mock.Character, mock.Player);

            var publicField = new FieldWithValue(mock.PublicField, "Public");

            MockedProject.AssignFieldValues(claim, publicField);

            _ = FieldSaveHelper.SaveCharacterFields(
                mock.Player.UserId,
                claim,
                new Dictionary <int, string?>()
            {
                { mock.HideForUnApprovedClaim.ProjectFieldId, "test" },
                { mock.CharacterField.ProjectFieldId, null },
            },
                _generator);

            mock.Character.FieldValuesShouldBe(new FieldWithValue(mock.HideForUnApprovedClaim, "test"), publicField);
            ShouldBeTestExtensions.ShouldBe(claim.JsonData, "{}");
        }
Example #27
0
 public ClaimServiceImpl(IUnitOfWork unitOfWork, IEmailService emailService,
                         IFieldDefaultValueGenerator fieldDefaultValueGenerator,
                         IAccommodationInviteService accommodationInviteService,
                         ICurrentUserAccessor currentUserAccessor
                         ) : base(unitOfWork, emailService,
                                  fieldDefaultValueGenerator, currentUserAccessor) => _accommodationInviteService = accommodationInviteService;
Example #28
0
 protected ClaimImplBase(IUnitOfWork unitOfWork, IEmailService emailService,
                         IFieldDefaultValueGenerator fieldDefaultValueGenerator) : base(unitOfWork)
 {
     EmailService = emailService;
     FieldDefaultValueGenerator = fieldDefaultValueGenerator;
 }
 public void SetUp()
 {
     _original = new MockedProject();
     generator = new MockedFieldDefaultValueGenerator();
 }
Example #30
0
 public ClaimServiceImpl(IUnitOfWork unitOfWork, IEmailService emailService,
                         IFieldDefaultValueGenerator fieldDefaultValueGenerator) : base(unitOfWork, emailService,
                                                                                        fieldDefaultValueGenerator)
 {
 }