csharp/Appdynamics/AppDynamics.DEXTER/Appdynamics-AppDynamics.DEXTER-63a3338/EPPlus/EPPlus-master/EPPlus-master/EPPlusTest/FormulaParsing/LexicalAnalysis/TokenFactoryTests.cs

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

namespace EPPlusTest.FormulaParsing.Lexicalastysis
{
    [TestClast]
    public clast TokenFactoryTests
    {
        private ITokenFactory _tokenFactory;
        private INameValueProvider _nameValueProvider;


        [TestInitialize]
        public void Setup()
        {
            var context = ParsingContext.Create();
            var excelDataProvider = A.Fake();
            _nameValueProvider = A.Fake();
            _tokenFactory = new TokenFactory(context.Configuration.FunctionRepository, _nameValueProvider);
        }

        [TestCleanup]
        public void Cleanup()
        {
      
        }

        [TestMethod]
        public void ShouldCreateAStringToken()
        {
            var input = "\"";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("\"", token.Value);
            astert.AreEqual(TokenType.String, token.TokenType);
        }

        [TestMethod]
        public void ShouldCreatePlusAsOperatorToken()
        {
            var input = "+";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("+", token.Value);
            astert.AreEqual(TokenType.Operator, token.TokenType);
        }

        [TestMethod]
        public void ShouldCreateMinusAsOperatorToken()
        {
            var input = "-";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("-", token.Value);
            astert.AreEqual(TokenType.Operator, token.TokenType);
        }

        [TestMethod]
        public void ShouldCreateMultiplyAsOperatorToken()
        {
            var input = "*";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("*", token.Value);
            astert.AreEqual(TokenType.Operator, token.TokenType);
        }

        [TestMethod]
        public void ShouldCreateDivideAsOperatorToken()
        {
            var input = "/";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("/", token.Value);
            astert.AreEqual(TokenType.Operator, token.TokenType);
        }

        [TestMethod]
        public void ShouldCreateEqualsAsOperatorToken()
        {
            var input = "=";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("=", token.Value);
            astert.AreEqual(TokenType.Operator, token.TokenType);
        }

        [TestMethod]
        public void ShouldCreateIntegerAsIntegerToken()
        {
            var input = "23";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("23", token.Value);
            astert.AreEqual(TokenType.Integer, token.TokenType);
        }

        [TestMethod]
        public void ShouldCreateBooleanAsBooleanToken()
        {
            var input = "true";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("true", token.Value);
            astert.AreEqual(TokenType.Boolean, token.TokenType);
        }

        [TestMethod]
        public void ShouldCreateDecimalAsDecimalToken()
        {
            var input = "23.3";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);

            astert.AreEqual("23.3", token.Value);
            astert.AreEqual(TokenType.Decimal, token.TokenType);
        }

        [TestMethod]
        public void CreateShouldReadFunctionsFromFuncRepository()
        {
            var input = "Text";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);
            astert.AreEqual(TokenType.Function, token.TokenType);
            astert.AreEqual("Text", token.Value);
        }

        [TestMethod]
        public void CreateShouldCreateExcelAddressAsExcelAddressToken()
        {
            var input = "A1";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);
            astert.AreEqual(TokenType.ExcelAddress, token.TokenType);
            astert.AreEqual("A1", token.Value);
        }

        [TestMethod]
        public void CreateShouldCreateExcelRangeAsExcelAddressToken()
        {
            var input = "A1:B15";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);
            astert.AreEqual(TokenType.ExcelAddress, token.TokenType);
            astert.AreEqual("A1:B15", token.Value);
        }

        [TestMethod]
        public void CreateShouldCreateExcelRangeOnOtherSheetAsExcelAddressToken()
        {
            var input = "ws!A1:B15";
            var token = _tokenFactory.Create(Enumerable.Empty(), input);
            astert.AreEqual(TokenType.ExcelAddress, token.TokenType);
            astert.AreEqual("WS!A1:B15", token.Value);
        }

        [TestMethod]
        public void CreateShouldCreateNamedValueAsExcelAddressToken()
        {
            var input = "NamedValue";
            A.CallTo(() => _nameValueProvider.IsNamedValue("NamedValue","")).Returns(true);
            A.CallTo(() => _nameValueProvider.IsNamedValue("NamedValue", null)).Returns(true);
            var token = _tokenFactory.Create(Enumerable.Empty(), input);
            astert.AreEqual(TokenType.NameValue, token.TokenType);
            astert.AreEqual("NamedValue", token.Value);
        }
    }
}