示例#1
0
        public void Merge_RightClockWithHigherTimestamp_ReturnsRightObject(
            TestType leftValue, TestType rightValue)
        {
            var lww    = new LWW_Register <TestType>(new LWW_RegisterElement <TestType>(leftValue, 0, false));
            var result = lww.Assign(rightValue, 1);

            Assert.Same(rightValue, result.Element.Value);
        }
示例#2
0
        public void Update_ListValues_SetsNewValues(TestType value)
        {
            var lww = new LWW_Register <TestType>(new LWW_RegisterElement <TestType>(value, 0, false));

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

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

            Assert.Equal(6, result.Element.Value.LongList.Count);
            Assert.Empty(result.Element.Value.IntArray);
        }
示例#3
0
        public void Update_ArrayValues_SetsNewValues(TestType value)
        {
            var lww = new LWW_Register <TestType>(new LWW_RegisterElement <TestType>(value, 0, false));

            var result = lww.Assign(JToken.Parse("{\"IntArray\": [1, 2, 3, 4, 5]}"), 1);

            result = result.Assign(JToken.Parse("{\"LongList\": []}"), 2);

            Assert.Equal(5, result.Element.Value.IntArray.Length);
            Assert.Empty(result.Element.Value.LongList);
        }
示例#4
0
        public void Update_NullableValues_SetsNulls(TestType value)
        {
            var lww = new LWW_Register <TestType>(new LWW_RegisterElement <TestType>(value, 0, false));

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

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

            Assert.Null(result.Element.Value.StringValue);
            Assert.Null(result.Element.Value.NullableLongValue);
            Assert.Null(result.Element.Value.ObjectValue);
        }
示例#5
0
        public void Update_InnerObjectValues_SetsNewValues(TestType value,
                                                           string stringValue, int intValue, decimal decimalValue)
        {
            var lww = new LWW_Register <TestType>(new LWW_RegisterElement <TestType>(value, 0, false));

            var result = lww.Assign(JToken.Parse($"{{\"ObjectValue\": {{ \"StringValue\": \"{stringValue}\", " +
                                                 $"\"DecimalValue\": {decimalValue}, \"IntValue\": {intValue}," +
                                                 $"\"NullableLongValue\": null }}}}"), 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);
        }
示例#6
0
        public void Update_OperationsWithLowerTimestamp_DoNotTakeEffect(TestType value,
                                                                        string stringValue, int intValue, decimal decimalValue, long longValue, Guid guidValue)
        {
            var lww = new LWW_Register <TestType>(new LWW_RegisterElement <TestType>(value, 10, false));

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

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

            Assert.Equal(result, lww);
            Assert.Equal(value, result.Element.Value);
        }
示例#7
0
        public void Update_NonExistingValues_DoNotTakeEffectForValues(TestType value,
                                                                      string stringValue, int intValue, decimal decimalValue, long longValue, Guid guidValue)
        {
            var lww = new LWW_Register <TestType>(new LWW_RegisterElement <TestType>(value, 0, false));

            var result = lww.Assign(JToken.Parse($"{{\"FooStringValue\": \"{stringValue}\"}}"), 1);

            result = result.Assign(JToken.Parse($"{{\"FooIntValue\": {intValue}}}"), 2);
            result = result.Assign(JToken.Parse($"{{\"FooDecimalValue\": {decimalValue}}}"), 3);
            result = result.Assign(JToken.Parse($"{{\"FooNullableLongValue\": {longValue}}}"), 4);
            result = result.Assign(JToken.Parse($"{{\"FooGuidValue\": \"{guidValue}\"}}"), 5);

            Assert.Equal(result, lww);
            Assert.Equal(value, result.Element.Value);
        }
示例#8
0
        public void Update_PrimitiveValuesWithMixedTimestamps_SetsNewValues(TestType value,
                                                                            string stringValue, int intValue, decimal decimalValue, long longValue, Guid guidValue)
        {
            var lww = new LWW_Register <TestType>(new LWW_RegisterElement <TestType>(value, 5, false));

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

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

            Assert.Equal(9, result.Element.Timestamp);
            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);
        }