예제 #1
0
            public void GenericUpdate_ShouldBeUpdate()
            {
                // arrange
                var sut = EditableValue.Update(Fixture.Create <int>());

                // act
                // assert
                sut.Should().BeUpdateVariant(because: "{0} is created using generic Update<T>() method and should be treated as 'update'", 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()));
        }
예제 #3
0
            public void UpdateOfDifferentValues_ShouldNotBeEqual()
            {
                // arrange
                var update1 = EditableValue <int> .Update(1);

                var update2 = EditableValue <int> .Update(2);

                // act
                // assert
                update1.Equals(update2).Should().BeFalse();
                update2.Equals(update1).Should().BeFalse();
            }
예제 #4
0
            public void UpdateOfSameValues_ShouldBeEqual()
            {
                // arrange
                var update1 = EditableValue <int> .Update(1);

                var update2 = EditableValue <int> .Update(1);

                // act
                // assert
                update1.Equals(update2).Should().BeTrue();
                update2.Equals(update1).Should().BeTrue();
            }
예제 #5
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();
            }
예제 #6
0
            public void Update_ShouldNotCallNoActionFunc()
            {
                // arrange
                var sut = EditableValue <int> .Update(Fixture.Create <int>());

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

                // assert
                match.Should().NotThrow(because: "matching 'update' should not call 'noAction' function");
            }
예제 #7
0
            public void Update_ShouldMatch()
            {
                // arrange
                var sut = EditableValue <int> .Update(Fixture.Create <int>());

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

                // assert
                result.Should().Be(State.Update);
            }
예제 #8
0
            public void Update_ShouldMapToUpdate()
            {
                // arrange
                int originalValue = Fixture.Create <int>();
                var sut           = EditableValue <int> .Update(originalValue);

                Func <int, string> map           = e => e.ToString();
                string             expectedValue = map(originalValue);

                // act
                var result = sut.Map(map);

                // assert
                result.Should().BeUpdateOf(expectedValue);
            }
예제 #9
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);
        }
예제 #10
0
 public static EditableValue <string> UpdateIfNotNullOrWhiteSpace(this string value) =>
 !string.IsNullOrWhiteSpace(value)
     ? EditableValue <string> .Update(value)
     : EditableValue <string> .NoAction();
예제 #11
0
 public static EditableValue <T> UpdateIfNotNull <T>(this T value) where T : class =>
 value != null
     ? EditableValue <T> .Update(value)
 : EditableValue <T> .NoAction();
예제 #12
0
 public static EditableValue <T> UpdateIfNotNull <T>(this T?value) where T : struct =>
 value != null
     ? EditableValue <T> .Update(value.Value)
 : EditableValue <T> .NoAction();