public void Update_ListValues_SetsNewValues(TestType value, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;
            var lww   = new LWW_RegisterWithVC <TestType>(new LWW_RegisterWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)), false));

            var result = lww.Assign(JToken.Parse("{\"IntArray\": []}"), new VectorClock(clock.Add(node, 1)));

            result = result.Assign(JToken.Parse("{\"LongList\": [-1000, 100, 200, 300, 400, 500]}"), new VectorClock(clock.Add(node, 2)));

            Assert.Equal(6, result.Element.Value.LongList.Count);
            Assert.Empty(result.Element.Value.IntArray);
        }
        public void Merge_RightClockWithHigherTimestamp_ReturnsRightObject(
            TestType leftValue, TestType rightValue, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var leftClock  = new VectorClock(clock.Add(node, 1));
            var rightClock = new VectorClock(clock.Add(node, 2));

            var lww    = new LWW_RegisterWithVC <TestType>(new LWW_RegisterWithVCElement <TestType>(leftValue, leftClock, false));
            var result = lww.Assign(rightValue, rightClock);

            Assert.Equal(rightValue, result.Element.Value);
        }
        public void Update_NullableValues_SetsNulls(TestType value, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;
            var lww   = new LWW_RegisterWithVC <TestType>(new LWW_RegisterWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)), false));

            var result = lww.Assign(JToken.Parse("{\"StringValue\": null}"), new VectorClock(clock.Add(node, 1)));

            result = result.Assign(JToken.Parse("{\"NullableLongValue\": null}"), new VectorClock(clock.Add(node, 2)));
            result = result.Assign(JToken.Parse("{\"ObjectValue\": null}"), new VectorClock(clock.Add(node, 3)));

            Assert.Null(result.Element.Value.StringValue);
            Assert.Null(result.Element.Value.NullableLongValue);
            Assert.Null(result.Element.Value.ObjectValue);
        }
        public void Update_InnerObjectValues_SetsNewValues(TestType value, Node node,
                                                           string stringValue, int intValue, decimal decimalValue)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;
            var lww   = new LWW_RegisterWithVC <TestType>(new LWW_RegisterWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)), false));

            var result = lww.Assign(JToken.Parse($"{{\"ObjectValue\": {{ \"StringValue\": \"{stringValue}\", " +
                                                 $"\"DecimalValue\": {decimalValue}, \"IntValue\": {intValue}," +
                                                 $"\"NullableLongValue\": null }}}}"), new VectorClock(clock.Add(node, 1)));

            Assert.Equal(stringValue, result.Element.Value.ObjectValue.StringValue);
            Assert.Equal(decimalValue, result.Element.Value.ObjectValue.DecimalValue);
            Assert.Equal(intValue, result.Element.Value.ObjectValue.IntValue);
            Assert.Null(result.Element.Value.ObjectValue.NullableLongValue);
        }
        public void Update_OperationsWithLowerTimestamp_DoNotTakeEffect(TestType value, Node node,
                                                                        string stringValue, int intValue, decimal decimalValue, long longValue, Guid guidValue)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;
            var lww   = new LWW_RegisterWithVC <TestType>(new LWW_RegisterWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 10)), false));

            var result = lww.Assign(JToken.Parse($"{{\"StringValue\": \"{stringValue}\"}}"), new VectorClock(clock.Add(node, 1)));

            result = result.Assign(JToken.Parse($"{{\"IntValue\": {intValue}}}"), new VectorClock(clock.Add(node, 2)));
            result = result.Assign(JToken.Parse($"{{\"DecimalValue\": {decimalValue}}}"), new VectorClock(clock.Add(node, 3)));
            result = result.Assign(JToken.Parse($"{{\"NullableLongValue\": {longValue}}}"), new VectorClock(clock.Add(node, 4)));
            result = result.Assign(JToken.Parse($"{{\"GuidValue\": \"{guidValue}\"}}"), new VectorClock(clock.Add(node, 5)));

            Assert.Equal(result, lww);
            Assert.Equal(value, result.Element.Value);
        }
        public void Update_PrimitiveValuesWithMixedTimestamps_SetsNewValues(TestType value, Node node,
                                                                            string stringValue, int intValue, decimal decimalValue, long longValue, Guid guidValue)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;
            var lww   = new LWW_RegisterWithVC <TestType>(new LWW_RegisterWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 5)), false));

            var result = lww.Assign(JToken.Parse($"{{\"StringValue\": \"{stringValue}\"}}"), new VectorClock(clock.Add(node, 1)));

            result = result.Assign(JToken.Parse($"{{\"IntValue\": {intValue}}}"), new VectorClock(clock.Add(node, 2)));
            result = result.Assign(JToken.Parse($"{{\"DecimalValue\": {decimalValue}}}"), new VectorClock(clock.Add(node, 3)));
            result = result.Assign(JToken.Parse($"{{\"NullableLongValue\": {longValue}}}"), new VectorClock(clock.Add(node, 8)));
            result = result.Assign(JToken.Parse($"{{\"GuidValue\": \"{guidValue}\"}}"), new VectorClock(clock.Add(node, 9)));

            Assert.Equal(new VectorClock(clock.Add(node, 9)), result.Element.VectorClock);
            Assert.Equal(value.StringValue, result.Element.Value.StringValue);
            Assert.Equal(value.IntValue, result.Element.Value.IntValue);
            Assert.Equal(value.DecimalValue, result.Element.Value.DecimalValue);
            Assert.Equal(longValue, result.Element.Value.NullableLongValue);
            Assert.Equal(guidValue, result.Element.Value.GuidValue);
        }