public void CorrectlySerializesComplexObject()
        {
            string fileName = $"{nameof(CorrectlySerializesComplexObject)}.json";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            var testCounter = new TestCounter();

            var complexObject = new ComplexObjectTest()
            {
                Age   = new DateTime(2014, 1, 6),
                Name  = "Devedse123",
                Timer = 400
            };

            var lss1    = new LineStateSaver(fileName);
            var result1 = lss1.Save(() => testCounter.ComplexCall(complexObject));

            var lss2    = new LineStateSaver(fileName);
            var result2 = lss2.Save(() => testCounter.ComplexCall(complexObject));

            Assert.Equal(result1, result2);
            Assert.Equal(1, testCounter.CallCount);

            File.Delete(fileName);
        }
        public void OnlyCallsMethodOncePerComplexObject()
        {
            var testCounter = new TestCounter();

            var complexObject1 = new ComplexObjectTest()
            {
                Age   = new DateTime(2018, 5, 2),
                Name  = "Devedse",
                Timer = 600
            };

            var complexObject2 = new ComplexObjectTest()
            {
                Age   = new DateTime(2018, 5, 2),
                Name  = "Devedse",
                Timer = 601
            };

            var lss = new LineStateSaver();

            lss.Save(() => testCounter.ComplexCall(complexObject1));
            lss.Save(() => testCounter.ComplexCall(complexObject1));
            lss.Save(() => testCounter.ComplexCall(complexObject2));
            lss.Save(() => testCounter.ComplexCall(complexObject1));
            lss.Save(() => testCounter.ComplexCall(complexObject1, complexObject2));
            lss.Save(() => testCounter.ComplexUnrelatedCall(complexObject2));

            Assert.Equal(2, testCounter.CallCount);
            Assert.Equal(1, testCounter.DoubleParametersCallCount);
            Assert.Equal(1, testCounter.ComplexUnrelatedCallCount);
        }
        public void ThrowsExceptionWhenMethodCallIsProvidedWithNestedMethodCalls()
        {
            var testCounter = new TestCounter();

            var lss = new LineStateSaver();
            var ex  = Assert.Throws <InvalidOperationException>(() => lss.Save(() => testCounter.SimpleCall(int.Parse("5"))));

            Assert.Contains("is not of type MemberExpression or ConstantExpression", ex.Message);
        }
Exemplo n.º 4
0
        public async Task ClearsTheDataWhenCallingClearFunction()
        {
            var testCounter = new TestCounter();

            var lss = new LineStateSaver();
            await lss.Save(() => testCounter.SimpleCallAsync(15));

            lss.Clear();
            await lss.Save(() => testCounter.SimpleCallAsync(15));

            Assert.Equal(2, testCounter.CallCount);
        }
Exemplo n.º 5
0
        public async Task OnlyCallsMethodOncePerSimpleObject()
        {
            var testCounter = new TestCounter();

            var lss = new LineStateSaver();
            await lss.Save(() => testCounter.SimpleCallAsync(15));
            await lss.Save(() => testCounter.SimpleCallAsync(15));
            await lss.Save(() => testCounter.SimpleCallAsync(17));
            await lss.Save(() => testCounter.SimpleCallAsync(15));
            await lss.Save(() => testCounter.SimpleCallAsync(17));
            await lss.Save(() => testCounter.SimpleCallAsync(15, 17));
            await lss.Save(() => testCounter.SimpleUnrelatedCallAsync(17));

            Assert.Equal(2, testCounter.CallCount);
            Assert.Equal(1, testCounter.DoubleParametersCallCount);
            Assert.Equal(1, testCounter.UnrelatedCallCount);
        }
Exemplo n.º 6
0
        public async Task CorrectlySerializesSimpleObject()
        {
            string fileName = $"{nameof(CorrectlySerializesSimpleObject)}.json";
            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            var testCounter = new TestCounter();

            var lss1 = new LineStateSaver(fileName);
            var result1 = await lss1.Save(() => testCounter.SimpleCallAsync(16));

            var lss2 = new LineStateSaver(fileName);
            var result2 = await lss2.Save(() => testCounter.SimpleCallAsync(16));

            Assert.Equal(result1, result2);
            Assert.Equal(1, testCounter.CallCount);

            File.Delete(fileName);
        }