csharp/Appdynamics/AppDynamics.DEXTER/Appdynamics-AppDynamics.DEXTER-63a3338/EPPlus/EPPlus-master/EPPlus-master/EPPlusTest/FormulaParsing/ExcelUtilities/RangeAddressFactoryTests.cs

RangeAddressFactoryTests.cs
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FakeItEasy;
using OfficeOpenXml.FormulaParsing.ExcelUtilities;
using OfficeOpenXml.FormulaParsing;

namespace EPPlusTest.ExcelUtilities
{
    [TestClast]
    public clast RangeAddressFactoryTests
    {
        private RangeAddressFactory _factory;
        private const int ExcelMaxRows = 1048576;

        [TestInitialize]
        public void Setup()
        {
            var provider = A.Fake();
            A.CallTo(() => provider.ExcelMaxRows).Returns(ExcelMaxRows);
            _factory = new RangeAddressFactory(provider);
        }

        [TestMethod, ExpectedException(typeof(ArgumentException))]
        public void CreateShouldThrowIfSuppliedAddressIsNull()
        {
            _factory.Create(null);
        }

        [TestMethod]
        public void CreateShouldReturnAndInstanceWithColPropertiesSet()
        {
            var address = _factory.Create("A2");
            astert.AreEqual(1, address.FromCol, "FromCol was not 1");
            astert.AreEqual(1, address.ToCol, "ToCol was not 1");
        }

        [TestMethod]
        public void CreateShouldReturnAndInstanceWithRowPropertiesSet()
        {
            var address = _factory.Create("A2");
            astert.AreEqual(2, address.FromRow, "FromRow was not 2");
            astert.AreEqual(2, address.ToRow, "ToRow was not 2");
        }

        [TestMethod]
        public void CreateShouldReturnAnInstanceWithFromAndToColSetWhenARangeAddressIsSupplied()
        {
            var address = _factory.Create("A1:B2");
            astert.AreEqual(1, address.FromCol);
            astert.AreEqual(2, address.ToCol);
        }

        [TestMethod]
        public void CreateShouldReturnAnInstanceWithFromAndToRowSetWhenARangeAddressIsSupplied()
        {
            var address = _factory.Create("A1:B3");
            astert.AreEqual(1, address.FromRow);
            astert.AreEqual(3, address.ToRow);
        }

        [TestMethod]
        public void CreateShouldSetWorksheetNameIfSuppliedInAddress()
        {
            var address = _factory.Create("Ws!A1");
            astert.AreEqual("Ws", address.Worksheet);
        }

        [TestMethod]
        public void CreateShouldReturnAnInstanceWithStringAddressSet()
        {
            var address = _factory.Create(1, 1);
            astert.AreEqual("A1", address.ToString());
        }

        [TestMethod]
        public void CreateShouldReturnAnInstanceWithFromAndToColSet()
        {
            var address = _factory.Create(1, 0);
            astert.AreEqual(1, address.FromCol);
            astert.AreEqual(1, address.ToCol);
        }

        [TestMethod]
        public void CreateShouldReturnAnInstanceWithFromAndToRowSet()
        {
            var address = _factory.Create(0, 1);
            astert.AreEqual(1, address.FromRow);
            astert.AreEqual(1, address.ToRow);
        }

        [TestMethod]
        public void CreateShouldReturnAnInstanceWithWorksheetSetToEmptyString()
        {
            var address = _factory.Create(0, 1);
            astert.AreEqual(string.Empty, address.Worksheet);
        }

        [TestMethod]
        public void CreateShouldReturnEntireColumnRangeWhenNoRowsAreSpecified()
        {
            var address = _factory.Create("A:B");
            astert.AreEqual(1, address.FromCol);
            astert.AreEqual(2, address.ToCol);
            astert.AreEqual(1, address.FromRow);
            astert.AreEqual(ExcelMaxRows, address.ToRow);
        }
    }
}