public void CreateDataset_Throws_ServerError()
        {
            IKeenHttpClientProvider httpClientProvider = null;

            if (UseMocks)
            {
                httpClientProvider = GetMockHttpClientProviderForDeleteAsync("{}", HttpStatusCode.InternalServerError);
            }

            var client = new KeenClient(SettingsEnv, httpClientProvider);

            Assert.Throws <KeenException>(() => client.CreateDataset(null));
        }
        public void CreateDataset_Success()
        {
            var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/GetDatasetDefinition.json");

            IKeenHttpClientProvider httpClientProvider = null;

            if (UseMocks)
            {
                httpClientProvider = GetMockHttpClientProviderForPutAsync(apiResponse);
            }

            var client     = new KeenClient(SettingsEnv, httpClientProvider);
            var newDataSet = CreateDatasetDefinition();
            var dataset    = client.CreateDataset(newDataSet);

            AssertDatasetIsPopulated(dataset);
        }
        public void CreateDataset_Throws_WrongKey()
        {
            var apiResponse = File.ReadAllText($"{GetApiResponsesPath()}/GetDatasetDefinition.json");

            IKeenHttpClientProvider httpClientProvider = null;

            if (UseMocks)
            {
                httpClientProvider = GetMockHttpClientProviderForPutAsync(apiResponse);
            }

            var brokenClient = new KeenClient(new ProjectSettingsProvider("5011efa95f546f2ce2000000",
                                                                          null,
                                                                          Environment.GetEnvironmentVariable(KeenConstants.KeenWriteKey) ?? "",
                                                                          Environment.GetEnvironmentVariable(KeenConstants.KeenReadKey) ?? "",
                                                                          GetServerUrl()),
                                              httpClientProvider);

            Assert.Throws <KeenException>(() => brokenClient.CreateDataset(CreateDatasetDefinition()));
        }
示例#4
0
        public void CreateDataset_Success()
        {
            var             result      = new DatasetDefinition();
            var             client      = new KeenClient(SettingsEnv);
            Mock <IDataset> datasetMock = null;

            if (UseMocks)
            {
                datasetMock = new Mock <IDataset>();
                datasetMock.Setup(m => m.CreateDatasetAsync(
                                      It.Is <DatasetDefinition>(n => n != null)))
                .ReturnsAsync(result);

                client.Datasets = datasetMock.Object;
            }

            var datasetDefinition = client.CreateDataset(new DatasetDefinition());

            Assert.IsNotNull(datasetDefinition);

            datasetMock?.VerifyAll();
        }
示例#5
0
        public void CreateDataset_Throws()
        {
            IKeenHttpClientProvider httpClientProvider = null;

            if (UseMocks)
            {
                httpClientProvider = GetMockHttpClientProviderForDeleteAsync("{}", HttpStatusCode.InternalServerError);
            }

            var client = new KeenClient(SettingsEnv, httpClientProvider);

            Assert.Throws <KeenException>(() => client.CreateDataset(null));

            var brokenClient = new KeenClient(new ProjectSettingsProvider("5011efa95f546f2ce2000000",
                                                                          null,
                                                                          Environment.GetEnvironmentVariable("KEEN_WRITE_KEY") ?? "",
                                                                          Environment.GetEnvironmentVariable("KEEN_READ_KEY") ?? "",
                                                                          Environment.GetEnvironmentVariable("KEEN_SERVER_URL") ?? KeenConstants.ServerAddress + "/" + KeenConstants.ApiVersion + "/"),
                                              httpClientProvider);

            Assert.Throws <KeenException>(() => brokenClient.CreateDataset(CreateDatasetDefinition()));
        }