Ejemplo n.º 1
0
            public void GenericNoAction_ShouldBeNoAction()
            {
                // arrange
                var sut = EditableValue.NoAction(Fixture.Create <int>());

                // act
                // assert
                sut.Should().BeNoActionVariant(because: "{0} is created using generic NoAction<T>() method and should be treated as 'noAction'", sut);
            }
Ejemplo n.º 2
0
            public void DomesticNoAction_ShouldBeNoAction()
            {
                // arrange
                var sut = EditableValue <int> .NoAction();

                // act
                // assert
                sut.Should().BeNoActionVariant(because: "{0} is created using domestic static NoAction() method and should be treated as 'noAction'", sut);
            }
        private static IEnumerable <EditableValue <string> > GetSerializeTestData()
        {
            yield return(EditableValue <string> .NoAction());

            yield return(EditableValue <string> .Update(null));

            yield return(EditableValue <string> .Update(string.Empty));

            yield return(EditableValue <string> .Update(System.Guid.NewGuid().ToString()));
        }
Ejemplo n.º 4
0
            public void NoAction_ShouldNotCallMapper()
            {
                // arrange
                var sut = EditableValue <int> .NoAction();

                // act
                Action map = () => sut.Map <int>(_ => throw new InvalidOperationException());

                // assert
                map.Should().NotThrow(because: "mapping 'noAction' should not call mapper function");
            }
Ejemplo n.º 5
0
            public void NoAction_ShouldMapToNoAction()
            {
                // arrange
                var sut = EditableValue <int> .NoAction();

                // act
                var result = sut.Map(e => e.ToString());

                // assert
                result.Should().BeNoActionVariant();
            }
Ejemplo n.º 6
0
            public void NoActionAndUpdateOfDefaultValue_ShouldNotBeEqual()
            {
                // arrange
                var noAction = EditableValue <int> .NoAction();

                var update = EditableValue <int> .Update(default(int));

                // act
                // assert
                noAction.Equals(update).Should().BeFalse();
                update.Equals(noAction).Should().BeFalse();
            }
Ejemplo n.º 7
0
            public void NoActionAndDefaultEditableValue_ShouldBeEqual()
            {
                // arrange
                var noAction = EditableValue <int> .NoAction();

                var @default = default(EditableValue <int>);

                // act
                // assert
                noAction.Equals(@default).Should().BeTrue();
                @default.Equals(noAction).Should().BeTrue();
            }
Ejemplo n.º 8
0
            public void NoAction_ShouldNotCallUpdateFunc()
            {
                // arrange
                var sut = EditableValue <int> .NoAction();

                // act
                Action match = () => sut.Match(
                    update: _ => throw new InvalidOperationException(),
                    noAction: () => State.NoAction);

                // assert
                match.Should().NotThrow(because: "matching 'noAction' should not call 'update' function");
            }
Ejemplo n.º 9
0
            public void NoAction_ShouldMatch()
            {
                // arrange
                var sut = EditableValue <int> .NoAction();

                // act
                var result = sut.Match(
                    update: _ => State.Update,
                    noAction: () => State.NoAction);

                // assert
                result.Should().Be(State.NoAction);
            }
Ejemplo n.º 10
0
        public bool TryBuild(out EditableValue <T> result)
        {
            T      value = Value;
            string state = State;

            if (string.IsNullOrEmpty(state) || string.Equals(state, Constants.Editable_NoActionState, StringComparison.OrdinalIgnoreCase))
            {
                result = EditableValue <T> .NoAction();

                return(true);
            }

            if (string.Equals(state, Constants.Editable_UpdateState, StringComparison.OrdinalIgnoreCase))
            {
                result = EditableValue <T> .Update(value);

                return(true);
            }

            result = default(EditableValue <T>);
            return(false);
        }
Ejemplo n.º 11
0
 public static EditableValue <T> NoActionIfNull <T>(this EditableValue <T>?value) =>
 value
 ?? EditableValue <T> .NoAction();
Ejemplo n.º 12
0
 public static EditableValue <string> UpdateIfNotNullOrWhiteSpace(this string value) =>
 !string.IsNullOrWhiteSpace(value)
     ? EditableValue <string> .Update(value)
     : EditableValue <string> .NoAction();
Ejemplo n.º 13
0
 public static EditableValue <T> UpdateIfNotNull <T>(this T value) where T : class =>
 value != null
     ? EditableValue <T> .Update(value)
 : EditableValue <T> .NoAction();
Ejemplo n.º 14
0
 public static EditableValue <T> UpdateIfNotNull <T>(this T?value) where T : struct =>
 value != null
     ? EditableValue <T> .Update(value.Value)
 : EditableValue <T> .NoAction();