Beispiel #1
0
        public async Task SetAsyncDataProvider_ReturnsValueFromSyncTask()
        {
            DataPackage dataPackage = new DataPackage();

            dataPackage.SetAsyncDataProvider(StandardDataFormats.Text, (formatId, deadline) =>
            {
                return Task.FromResult<object>("Test text");
            });

            DataPackageView dataPackageView = dataPackage.GetView();
            string result = await dataPackageView.GetTextAsync();

            Assert.AreEqual("Test text", result);
        }
Beispiel #2
0
        public async Task SetAsyncDataProvider_ReturnsValueFromAsyncTask()
        {
            DataPackage dataPackage = new DataPackage();

            dataPackage.SetAsyncDataProvider(StandardDataFormats.Text, async (formatId, deadline) =>
                {
                    await Task.Delay(200);
                    return "Test text";
                });

            DataPackageView dataPackageView = dataPackage.GetView();
            string result = await dataPackageView.GetTextAsync();

            Assert.AreEqual("Test text", result);
        }
Beispiel #3
0
        public async Task SetAsyncDataProvider_PassesDeadlineToMethod()
        {
            DataPackage dataPackage = new DataPackage();

            DateTimeOffset deadlineValue = DateTimeOffset.MinValue;

            dataPackage.SetAsyncDataProvider(StandardDataFormats.Text, (formatId, deadline) =>
            {
                deadlineValue = deadline;
                return Task.FromResult<object>("Test text");
            });

            DataPackageView dataPackageView = dataPackage.GetView();
            string result = await dataPackageView.GetTextAsync();

            Assert.AreNotEqual(DateTimeOffset.MinValue, deadlineValue);
        }
Beispiel #4
0
        public async Task SetAsyncDataProvider_PassesFormatIdToMethod()
        {
            DataPackage dataPackage = new DataPackage();

            string formatIdValue = null;

            dataPackage.SetAsyncDataProvider(StandardDataFormats.Text, (formatId, deadline) =>
            {
                formatIdValue = formatId;
                return Task.FromResult<object>("Test text");
            });

            DataPackageView dataPackageView = dataPackage.GetView();
            string result = await dataPackageView.GetTextAsync();

            Assert.AreEqual(StandardDataFormats.Text, formatIdValue);
        }