<commit_before>﻿/**
 * Copyright 2016 d-fens GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
 using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using biz.dfch.CS.Osram.Lightify.Client.Model;
using Telerik.JustMock;
using biz.dfch.CS.Web.Utilities.Rest;

namespace biz.dfch.CS.Osram.Lightify.Client.Tests
{
    [TestClass]
    public class ClientGetApiVersionTest
    {
        [TestMethod]
        public void GetApiVersionReturnsVersionOfOsramLightifyApi()
        {
            // Arrange
            // DFTODO - replace with object -> serialize
            var apiVersionAsJson = "{\"apiversion\":\"1.0.0\"}";
            var client = new Client(TestConstants.OSRAM_LIGHTIFY_BASE_URI);

            client.UserInformation = new UserInformation()
            {
                UserId = TestConstants.USER_ID,
                Username = TestConstants.USERNAME,
                Password = <PASSWORD>,
                SerialNumber = TestConstants.SERIAL_NUMBER,
                SecurityToken = TestConstants.SECURITY_TOKEN
            };

            var restCallExecutor = Mock.Create<RestCallExecutor>();
            var requestUri = new Uri(TestConstants.OSRAM_LIGHTIFY_BASE_URI, Lightify.Client.Constants.ApiOperation.VERSION);
            Mock.Arrange(() => restCallExecutor.Invoke(HttpMethod.Get, requestUri.AbsoluteUri, Arg.IsAny<Dictionary<string, string>>(), Arg.AnyString))
                .IgnoreInstance()
                .Returns(apiVersionAsJson)
                .OccursOnce();

            // Act
            var apiVersion = client.GetApiVersion();

            // Assert
            Assert.IsNotNull(apiVersion);
            Assert.AreEqual(1, apiVersion.Major);
            Assert.AreEqual(0, apiVersion.Minor);
            Assert.AreEqual(0, apiVersion.Build);

            Mock.Assert(restCallExecutor);
        }
    }
}<commit_msg>ApiVersionTest<commit_after>﻿/**
 * Copyright 2016 d-fens GmbH
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
 using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using biz.dfch.CS.Osram.Lightify.Client.Model;
using Telerik.JustMock;
using biz.dfch.CS.Web.Utilities.Rest;

namespace biz.dfch.CS.Osram.Lightify.Client.Tests
{
    [TestClass]
    public class ClientGetApiVersionTest
    {
        [TestMethod]
        public void GetApiVersionReturnsVersionOfOsramLightifyApi()
        {
            // Arrange
            var major = 1;
            var minor = 2;
            var build = 3;
            var version = new Version(major, minor, build, 0);
            var apiVersionResponse = new ApiVersion()
            {
                Version = version
            };

            var client = new Client(TestConstants.OSRAM_LIGHTIFY_BASE_URI);

            client.UserInformation = new UserInformation()
            {
                UserId = TestConstants.USER_ID,
                Username = TestConstants.USERNAME,
                Password = <PASSWORD>,
                SerialNumber = TestConstants.SERIAL_NUMBER,
                SecurityToken = TestConstants.SECURITY_TOKEN
            };

            var restCallExecutor = Mock.Create<RestCallExecutor>();
            var requestUri = new Uri(TestConstants.OSRAM_LIGHTIFY_BASE_URI, Constants.ApiOperation.VERSION);
            Mock.Arrange(() => restCallExecutor.Invoke(HttpMethod.Get, requestUri.AbsoluteUri, Arg.IsAny<Dictionary<string, string>>(), Arg.AnyString))
                .IgnoreInstance()
                .Returns(apiVersionResponse.SerializeObject())
                .OccursOnce();

            // Act
            var result = client.GetApiVersion();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(major, result.Major);
            Assert.AreEqual(minor, result.Minor);
            Assert.AreEqual(build, result.Build);

            Mock.Assert(restCallExecutor);
        }
    }
}
{'fraction_non_alphanumeric': 0.09083895853423336, 'fraction_numerical': 0.005014464802314368, 'mean_word_length': 2.4321641297154204, 'pattern_counts': {'":': 1, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4155253', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1346, 'n_words': 352}