Exemplo n.º 1
0
        public PrintCharacterViewModel
            (int currentUserId, [NotNull] Character character, IReadOnlyCollection <PlotElement> plots)
            : base(character)
        {
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }
            CharacterDescription = character.Description.ToHtmlString();

            var plotElements = character.GetOrderedPlots(character.SelectPlots(plots)).ToArray();

            Plots =
                plotElements
                .ToViewModels(currentUserId, character)
                .ToArray();

            Handouts =
                plotElements.Where(e => e.ElementType == PlotElementType.Handout)
                .Select(e => e.Texts.Content.ToPlainText())
                .ToArray();


            PlayerPhoneNumber = character.ApprovedClaim?.Player.Extra?.PhoneNumber;
            Fields            = new CustomFieldsViewModel(currentUserId, character, disableEdit: true, onlyPlayerVisible: true, wherePrintEnabled: true);
        }
Exemplo n.º 2
0
        public void ShowPublicFieldToAnon()
        {
            var vm          = new CustomFieldsViewModel(null, Mock.Character);
            var publicField = vm.FieldById(Mock.PublicField.ProjectFieldId);

            Assert.IsTrue(publicField?.CanView ?? true);
            Assert.IsNotNull(publicField?.Value);
        }
Exemplo n.º 3
0
        public void ShowPublicFieldToAnonEvenIfEditDisabled()
        {
            MockedProject.AssignFieldValues(Mock.Character, new FieldWithValue(Mock.PublicField, "1"));

            var vm          = new CustomFieldsViewModel(currentUserId: null, character: Mock.Character, disableEdit: true);
            var publicField = vm.FieldById(Mock.PublicField.ProjectFieldId);

            publicField.ShouldNotBeNull();
            publicField.CanView.ShouldBeTrue();
        }
Exemplo n.º 4
0
        public void AllowCharactersFieldOnAddClaimForCharacterTest()
        {
            var vm             = new CustomFieldsViewModel(Mock.Player.UserId, (IClaimSource)Mock.Character);
            var characterField = vm.FieldById(Mock.CharacterField.ProjectFieldId);

            Assert.IsNotNull(characterField);
            Assert.IsFalse(characterField.CanView);
            Assert.IsNull(characterField.Value);

            Assert.IsTrue(characterField.CanEdit);
        }
Exemplo n.º 5
0
        public void AllowCharactersFieldOnAddClaimTest()
        {
            var vm             = new CustomFieldsViewModel(Mock.Player.UserId, (IClaimSource)Mock.Character);
            var characterField = vm.FieldById(Mock.CharacterField.ProjectFieldId);

            characterField.ShouldNotBeNull();
            characterField.CanView.ShouldBeFalse();
            characterField.Value.ShouldBeNull();

            characterField.CanEdit.ShouldBeTrue();
        }
Exemplo n.º 6
0
        public EditCharacterViewModel Fill(Character field, int currentUserId)
        {
            Navigation = CharacterNavigationViewModel.FromCharacter(field, CharacterNavigationPage.Editing,
                                                                    currentUserId);
            Fields = new CustomFieldsViewModel(currentUserId, field);

            ActiveClaimsCount = field.Claims.Count(claim => claim.IsActive);
            IsActive          = field.IsActive;

            return(this);
        }
Exemplo n.º 7
0
        public void AllowCharactersFieldOnAddClaimForCharacterTest()
        {
            var vm             = new CustomFieldsViewModel(Mock.Player.UserId, (IClaimSource)Mock.Character);
            var characterField = vm.Field(Mock.CharacterField);

            characterField.ShouldNotBeNull();

            characterField.ShouldBeHidden();
            characterField.ShouldNotHaveValue();

            characterField.ShouldBeEditable();
        }
Exemplo n.º 8
0
        public void AllowCharactersFieldOnAddClaimForGroupTest()
        {
            var vm             = new CustomFieldsViewModel(Mock.Player.UserId, Mock.Group);
            var characterField = vm.FieldById(Mock.CharacterField.ProjectFieldId);

            characterField.ShouldNotBeNull();
            characterField.ShouldBeHidden();

            characterField.ShouldNotHaveValue();

            characterField.ShouldBeEditable();
        }
Exemplo n.º 9
0
 public CharacterDetailsViewModel(int?currentUserIdOrDefault, Character character, IEnumerable <PlotElement> plots)
 {
     Description  = character.Description.ToHtmlString();
     Player       = character.ApprovedClaim?.Player;
     HasAccess    = character.HasAnyAccess(currentUserIdOrDefault);
     ParentGroups = new CharacterParentGroupsViewModel(character, character.HasMasterAccess(currentUserIdOrDefault));
     HidePlayer   = character.HidePlayerForCharacter;
     Navigation   =
         CharacterNavigationViewModel.FromCharacter(character, CharacterNavigationPage.Character,
                                                    currentUserIdOrDefault);
     Fields = new CustomFieldsViewModel(currentUserIdOrDefault, character, disableEdit: true);
     Plot   = plots.ToViewModels(currentUserIdOrDefault, character);
 }
Exemplo n.º 10
0
        public void DoNotDiscloseOriginalFieldValuesOnAddTest()
        {
            var mock = new MockedProject();

            var vm = new CustomFieldsViewModel(mock.Player.UserId, (IClaimSource)mock.Character);

            var characterField = vm.Field(mock.CharacterField);

            characterField.ShouldNotBeNull();
            characterField.ShouldBeHidden();
            characterField.ShouldNotHaveValue();

            characterField.ShouldBeEditable();
        }
Exemplo n.º 11
0
        public void ProperlyShowConditionalHeaderTest()
        {
            var conditionalHeader = Mock.CreateConditionalHeader();
            var claim             = Mock.CreateApprovedClaim(Mock.Character, Mock.Player);

            var vm             = new CustomFieldsViewModel(Mock.Player.UserId, claim);
            var characterField = vm.FieldById(conditionalHeader.ProjectFieldId);

            characterField.ShouldNotBeNull();
            characterField.ShouldBeVisible();
            characterField.ShouldNotHaveValue();

            characterField.ShouldBeEditable();
        }
Exemplo n.º 12
0
        public void ProperlyShowConditionalHeaderTest()
        {
            var mock  = new MockedProject();
            var claim = mock.CreateApprovedClaim(mock.Character, mock.Player);

            var vm             = new CustomFieldsViewModel(mock.Player.UserId, claim);
            var characterField = vm.FieldById(mock.ConditionalHeader.ProjectFieldId);

            Assert.IsNotNull(characterField);
            Assert.IsTrue(characterField.CanView);
            Assert.IsNull(characterField.Value);

            Assert.IsTrue(characterField.CanEdit);
        }
Exemplo n.º 13
0
        public void ProperlyHideConditionalHeader()
        {
            var conditionalHeader = Mock.CreateConditionalHeader();
            var claim             = Mock.CreateApprovedClaim(Mock.CharacterWithoutGroup, Mock.Player);

            var vm             = new CustomFieldsViewModel(Mock.Player.UserId, claim);
            var characterField = vm.FieldById(conditionalHeader.ProjectFieldId);

            characterField.ShouldNotBeNull();
            characterField.ShouldBeHidden();
            characterField.ShouldNotHaveValue();

            characterField.ShouldBeReadonly();
        }
        public void DoNotDiscloseOriginalFieldValuesTest()
        {
            var mock  = new MockedProject();
            var claim = mock.CreateClaim(mock.Character, mock.Player);

            var vm = new CustomFieldsViewModel(mock.Player.UserId, claim);

            var characterField = vm.Field(mock.CharacterField);

            _ = characterField.ShouldNotBeNull();
            characterField.ShouldBeHidden();
            characterField.ShouldNotHaveValue();

            characterField.ShouldBeEditable();
        }
Exemplo n.º 15
0
        public void DoNotDiscloseOriginalFieldValuesTest()
        {
            var mock  = new MockedProject();
            var claim = mock.CreateClaim(mock.Character, mock.Player);

            var vm = new CustomFieldsViewModel(mock.Player.UserId, claim);

            var characterField = vm.FieldById(mock.CharacterField.ProjectFieldId);

            Assert.IsNotNull(characterField);
            Assert.IsFalse(characterField.CanView);
            Assert.IsNull(characterField.Value);

            Assert.IsTrue(characterField.CanEdit);
        }
Exemplo n.º 16
0
        public void AllowShadowCharacterFieldsTest()
        {
            var mock  = new MockedProject();
            var claim = mock.CreateClaim(mock.Character, mock.Player);

            MockedProject.AssignFieldValues(claim, new FieldWithValue(mock.CharacterField, "test"));

            var vm = new CustomFieldsViewModel(mock.Player.UserId, claim);

            var characterField = vm.FieldById(mock.CharacterField.ProjectFieldId);

            characterField.ShouldNotBeNull();
            characterField.ShouldBeHidden();
            characterField.Value.ShouldBe("test");

            characterField.ShouldBeEditable();
        }
        public void Insert()
        {
            // Arrange - Create a new account view model
            var newCustomFieldsViewModel = new CustomFieldsViewModel()
            {
                OrganisationId = requiredOrganisationId,
                FieldType      = 1
            };


            // Act - send this to the insert method on the account service logic
            var Response = _customFieldsService.Insert(newCustomFieldsViewModel, null);


            // Assert
            Assert.IsTrue(Response.Success);
        }
Exemplo n.º 18
0
        public void AllowShadowCharacterFieldsTest()
        {
            var mock  = new MockedProject();
            var claim = mock.CreateClaim(mock.Character, mock.Player);

            claim.JsonData = $"{{\"{mock.CharacterField.ProjectFieldId}\":\"test\"}}";

            var vm = new CustomFieldsViewModel(mock.Player.UserId, claim);

            var characterField = vm.FieldById(mock.CharacterField.ProjectFieldId);

            Assert.IsNotNull(characterField);
            Assert.IsFalse(characterField.CanView);
            Assert.AreEqual("test", characterField.Value);

            Assert.IsTrue(characterField.CanEdit);
        }
Exemplo n.º 19
0
        public EditCharacterViewModel Fill(Character field, int currentUserId)
        {
            Navigation = CharacterNavigationViewModel.FromCharacter(field, CharacterNavigationPage.Editing,
                                                                    currentUserId);
            Fields = new CustomFieldsViewModel(currentUserId, field);

            ActiveClaimsCount        = field.Claims.Count(claim => claim.IsActive);
            IsActive                 = field.IsActive;
            IsAcceptingClaimsEnabled = field.ApprovedClaim == null;

            IsAcceptingClaims = IsAcceptingClaims && IsAcceptingClaimsEnabled;
            CreatedAt         = field.CreatedAt;
            UpdatedAt         = field.UpdatedAt;
            CreatedBy         = field.CreatedBy;
            UpdatedBy         = field.UpdatedBy;

            return(this);
        }
Exemplo n.º 20
0
        public CharacterDetailsViewModel(int?currentUserIdOrDefault, Character character, IReadOnlyCollection <PlotElement> plots, IUriService uriService)
        {
            Player       = character.ApprovedClaim?.Player;
            HasAccess    = character.HasAnyAccess(currentUserIdOrDefault);
            ParentGroups = new CharacterParentGroupsViewModel(character, character.HasMasterAccess(currentUserIdOrDefault));
            HidePlayer   = character.HidePlayerForCharacter;
            Navigation   =
                CharacterNavigationViewModel.FromCharacter(character, CharacterNavigationPage.Character,
                                                           currentUserIdOrDefault);
            Fields = new CustomFieldsViewModel(currentUserIdOrDefault, character, disableEdit: true);
            Plot   = PlotDisplayViewModel.Published(plots, currentUserIdOrDefault, character, uriService);

            HasMasterAccess = character.HasMasterAccess(currentUserIdOrDefault);
            CreatedAt       = character.CreatedAt;
            UpdatedAt       = character.UpdatedAt;
            CreatedBy       = character.CreatedBy;
            UpdatedBy       = character.UpdatedBy;
        }
Exemplo n.º 21
0
        public void PublicCharactersFieldValueOnAddClaimAreReadonlyIfNotShowForUnApprovedClaims()
        {
            var field = Mock.CreateField(new ProjectField()
            {
                IsPublic = true, CanPlayerEdit = true, ShowOnUnApprovedClaims = false
            });
            var value = new FieldWithValue(field, "xxx");

            Mock.Character.JsonData = new[] { value }.SerializeFields();

            var vm             = new CustomFieldsViewModel(Mock.Player.UserId, (IClaimSource)Mock.Character);
            var characterField = vm.Field(field);

            characterField.ShouldNotBeNull();
            characterField.ShouldBeVisible();

            characterField.Value.ShouldBe("xxx");

            characterField.ShouldBeReadonly();
        }
        public CharacterListItemViewModel([NotNull] Character character, int currentUserId, IEnumerable <ClaimProblem> problems, IReadOnlyCollection <PlotElement> plots)
        {
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }


            if (character.ApprovedClaim != null)
            {
                BusyStatus      = CharacterBusyStatusView.HasPlayer;
                ApprovedClaimId = character.ApprovedClaim.ClaimId;
                Player          = character.ApprovedClaim.Player;
            }
            else if (character.Claims.Any(c => c.IsActive))
            {
                BusyStatus = CharacterBusyStatusView.Discussed;
            }
            else if (character.IsAcceptingClaims)
            {
                BusyStatus = CharacterBusyStatusView.NotSend;
            }
            else
            {
                BusyStatus = CharacterBusyStatusView.Npc;
            }
            Name        = character.CharacterName;
            CharacterId = character.CharacterId;
            ProjectId   = character.ProjectId;
            Fields      = new CustomFieldsViewModel(currentUserId, character, disableEdit: true); //This disable edit will speed up some requests.
            Problems    = problems.Select(p => new ProblemViewModel(p)).ToList();

            IndReadyPlotsCount = plots.Count(p => p.IsCompleted && p.TargetCharacters.Select(c => c.CharacterId).Contains(character.CharacterId));
            IndAllPlotsCount   = plots.Count(p => p.IsActive && p.TargetCharacters.Select(c => c.CharacterId).Contains(character.CharacterId));
            ColReadyPlotsCount = plots.Count(p => p.IsCompleted && !p.TargetCharacters.Select(c => c.CharacterId).Contains(character.CharacterId));
            ColAllPlotsCount   = plots.Count(p => p.IsActive && !p.TargetCharacters.Select(c => c.CharacterId).Contains(character.CharacterId));
            Groups             = new CharacterParentGroupsViewModel(character, character.HasMasterAccess(currentUserId));
        }
Exemplo n.º 23
0
        public PrintCharacterViewModel
            (int currentUserId, [NotNull] Character character, IReadOnlyCollection <PlotElement> plots, IUriService uriService)
            : base(character)
        {
            if (character == null)
            {
                throw new ArgumentNullException(nameof(character));
            }

            var plotElements = character.GetOrderedPlots(character.SelectPlots(plots)).ToArray();

            Plots = PlotDisplayViewModel.Published(plotElements, currentUserId, character, uriService);

            Handouts =
                plotElements.Where(e => e.ElementType == PlotElementType.Handout && e.IsActive)
                .Select(e => e.PublishedVersion())
                .Where(e => e != null)
                .Select(e => new HandoutListItemViewModel(e.Content.ToPlainText(), e.AuthorUser))
                .ToArray();

            PlayerPhoneNumber = character.ApprovedClaim?.Player.Extra?.PhoneNumber;
            Fields            = new CustomFieldsViewModel(currentUserId, character, disableEdit: true, onlyPlayerVisible: true, wherePrintEnabled: true);
        }
Exemplo n.º 24
0
 protected void FillFields(Character field, int currentUserId)
 {
     Fields = new CustomFieldsViewModel(currentUserId, field);
 }
 protected void FillFields(Character field, int currentUserId)
 {
     Fields         = new CustomFieldsViewModel(currentUserId, field);
     LegacyNameMode = field.Project.Details.CharacterNameLegacyMode;
 }
Exemplo n.º 26
0
        public void HideUnApprovedFieldOnAddClaimTest()
        {
            var vm = new CustomFieldsViewModel(Mock.Player.UserId, Mock.Group);

            (vm.FieldById(Mock.HideForUnApprovedClaim.ProjectFieldId)?.CanView ?? false).ShouldBeFalse();
        }
Exemplo n.º 27
0
        public void HideMasterOnlyFieldOnAddClaimTest()
        {
            var vm = new CustomFieldsViewModel(Mock.Player.UserId, Mock.Group);

            (vm.FieldById(Mock.MasterOnlyField.ProjectFieldId)?.CanView ?? false).ShouldBeFalse();
        }
Exemplo n.º 28
0
        public void ShowPublicFieldToAnonEvenIfEditDisabled()
        {
            var vm = new CustomFieldsViewModel(null, Mock.Character, disableEdit: true);

            Assert.IsTrue(vm.FieldById(Mock.PublicField.ProjectFieldId)?.CanView ?? true);
        }