Exemplo n.º 1
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.º 2
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);
        }
Exemplo n.º 3
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.º 4
0
        public async Task ThrowsExceptionWhenMethodCallIsProvidedWithNestedMethodCalls()
        {
            var testCounter = new TestCounter();

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

            Assert.Contains("is not of type MemberExpression or ConstantExpression", ex.Message);
        }