Beispiel #1
0
        public void ShouldNotChangeStringWhenClassIsNotGeneric()
        {
            string originalClass   = typeof(String).AssemblyQualifiedName;
            string translatedClass = NotationHelper.ParseClrNotationToGenericName(originalClass);

            Assert.AreEqual(originalClass, translatedClass);
        }
Beispiel #2
0
        public void ShouldNotChangeEmptyToCLRNotation()
        {
            string genericClass    = "SmartClientFactoryPackage.Tests.NormalClass";
            string translatedClass = NotationHelper.ParseGenericNameToCLRNotation(genericClass);

            Assert.AreEqual(genericClass, translatedClass);
            Assert.IsTrue(translatedClass.StartsWith("SmartClientFactoryPackage.Tests.NormalClass"));
        }
Beispiel #3
0
        public void MoveCodesParsed(string moveCode, int expectedFrom, int expectedTo, int promotionPiece)
        {
            var move = NotationHelper.ParseMoveCode(moveCode);

            Assert.AreEqual(expectedFrom, move.StartSquare);
            Assert.AreEqual(expectedTo, move.EndSquare);
            Assert.AreEqual(promotionPiece, move.PromotionPiece);
        }
Beispiel #4
0
        public void ShouldChangeStringToNamedArgumentWhenClassIsGenericWith11GenericParameters()
        {
            string originalClass   = typeof(GenericClass11 <, , , , , , , , , ,>).AssemblyQualifiedName;
            string translatedClass = NotationHelper.ParseClrNotationToGenericName(originalClass);

            Assert.AreNotEqual(originalClass, translatedClass);
            Assert.IsTrue(translatedClass.StartsWith("SmartClientFactoryPackage.Tests.GenericClass11<A,B,C,D,E,F,G,H,I,J,K>"));
        }
Beispiel #5
0
        public void ShouldChangeNamedArgumentToCLRNotation()
        {
            string genericClass    = "SmartClientFactoryPackage.Tests.GenericClass2<T,G>";
            string translatedClass = NotationHelper.ParseGenericNameToCLRNotation(genericClass);

            Assert.AreNotEqual(genericClass, translatedClass);
            Assert.IsTrue(translatedClass.StartsWith("SmartClientFactoryPackage.Tests.GenericClass2`2"));
        }
Beispiel #6
0
        public void ShouldChangeStringWhenClassIsGeneric()
        {
            string originalClass   = typeof(GenericClass <string>).AssemblyQualifiedName;
            string translatedClass = NotationHelper.ParseClrNotationToGenericName(originalClass);

            Assert.AreNotEqual(originalClass, translatedClass);
            Assert.IsTrue(translatedClass.StartsWith("SmartClientFactoryPackage.Tests.GenericClass<String>"));
        }
        public static object GetProxyFactory(Type proxyType, string language)
        {
            object newValue = null;

            if (proxyType != null)
            {
                ProxyTechnology proxyTech = GetProxyTechnology(proxyType);
                if (proxyTech == ProxyTechnology.Asmx)
                {
                    newValue = WebServiceProxyFactoryName;
                }
                else if (proxyTech == ProxyTechnology.Wcf)
                {
                    Type genericImplementation = proxyType.BaseType;
                    while (genericImplementation != typeof(Object))
                    {
                        if (genericImplementation.IsGenericType &&
                            typeof(ClientBase <>).IsAssignableFrom(genericImplementation.GetGenericTypeDefinition()))
                        {
                            string wrappedServiceTypeName = string.Empty;
                            Type[] generigArguments       = genericImplementation.GetGenericArguments();
                            if (generigArguments.Length == 1)
                            {
                                wrappedServiceTypeName = generigArguments[0].FullName;
                            }

                            string clrNotationFactoryTypeName = WCFProxyFactoryGenericName;
                            string genericFactoryTypeName     = NotationHelper.RemoveTrailingCLRChars(clrNotationFactoryTypeName);
                            newValue = string.Format(GetSelectedLanguageGenericFormat(language), genericFactoryTypeName, wrappedServiceTypeName);
                            break;
                        }
                        genericImplementation = genericImplementation.BaseType;
                    }
                }

                if (newValue == null)
                {
                    newValue = ObjectProxyFactoryName;
                }
            }
            return(newValue);
        }
Beispiel #8
0
 public void squareStringParsedTosquareId(string squareString, int expectedsquareId)
 {
     Assert.AreEqual(expectedsquareId, NotationHelper.ParseSquare(squareString));
 }
Beispiel #9
0
 public void PieceConvertedToTheChar(int piece, char expectedChar)
 {
     Assert.AreEqual(expectedChar, NotationHelper.GetPieceChar(piece));
 }
Beispiel #10
0
        public void ShouldRemoveCLRNotationCharacters()
        {
            string clrNotation = typeof(GenericClass <>).FullName;

            Assert.AreEqual("SmartClientFactoryPackage.Tests.GenericClass", NotationHelper.RemoveTrailingCLRChars(clrNotation));
        }
Beispiel #11
0
 public void MovesConvertedToStringCodes(Move move, string expectedMoveCode)
 {
     Assert.AreEqual(expectedMoveCode, NotationHelper.GetMoveCode(move));
 }
Beispiel #12
0
        public Position Read(string fenString)
        {
            try
            {
                PieceArray whitePieces = new PieceArray(0),
                           blackPieces = new PieceArray(1);
                var  chunks            = fenString.Split();
                bool isChess960        = !chunks[2].ToLower().Any(c => c == 'q' || c == 'k');

                var boardChunks = chunks[0].Split(new[] { '/' });

                for (int rank = 0; rank < Constants.BoardRanks; rank++)
                {
                    var rankChunk = boardChunks[rank];
                    int file      = 0;
                    foreach (var item in rankChunk)
                    {
                        if (int.TryParse(item.ToString(), out var gap))
                        {
                            file += gap;
                        }
                        else
                        {
                            int square = rank * Constants.BoardFiles + file;
                            int piece  = NotationHelper.GetPiece(item);
                            if ((piece & Piece.White) != 0)
                            {
                                whitePieces.Add(piece & Piece.TypeMask, square);
                            }
                            else
                            {
                                blackPieces.Add(piece & Piece.TypeMask, square);
                            }

                            file++;
                        }
                    }
                }

                GameState initialGameState = new GameState();

                if (chunks[2] != "-")
                {
                    initialGameState[0] = NotationHelper.GetCastlingOptions(chunks[2], true, isChess960, whitePieces.Rooks, whitePieces.King);
                    initialGameState[1] = NotationHelper.GetCastlingOptions(chunks[2], false, isChess960, blackPieces.Rooks, blackPieces.King);
                }

                if (chunks[3] != "-")
                {
                    initialGameState.EnPassantSquare = NotationHelper.ParseSquare(chunks[3]);
                }

                int totalMoves = 1;
                if (chunks.Length > 4)
                {
                    initialGameState.HalfMoveClock = int.Parse(chunks[4]);
                    totalMoves = int.Parse(chunks[5]);
                }

                return(new Position(whitePieces, blackPieces, initialGameState)
                {
                    WhiteToMove = chunks[1].ToLower() == "w",
                    TotalMoves = totalMoves,
                    IsChess960 = isChess960
                });
            }
            catch (Exception e)
            {
                throw new FormatException($"Wrong fen string: {fenString}", e);
            }
        }
Beispiel #13
0
 public void InvalidsquareConvertedToStringThrows(int square)
 {
     Assert.Throws <ArgumentException>(() => NotationHelper.GetSquareString(square));
 }
Beispiel #14
0
 public void squareConvertedToString(int square, string expectedsquareString)
 {
     Assert.AreEqual(expectedsquareString, NotationHelper.GetSquareString(square));
 }
Beispiel #15
0
 public void InvalidPieceCharConvertedToIntThrows(char pieceChar)
 {
     Assert.Throws <ArgumentException>(() => NotationHelper.GetPiece(pieceChar));
 }
Beispiel #16
0
 public void PieceCharConvertedToInt(char pieceChar, int expectedPieceCode)
 {
     Assert.AreEqual(expectedPieceCode, NotationHelper.GetPiece(pieceChar));
 }
Beispiel #17
0
 public void InvalidPieceConvertedToTheCharThrows(int piece)
 {
     Assert.Throws <ArgumentException>(() => NotationHelper.GetPieceChar(piece));
 }
Beispiel #18
0
        public string Write(Position position, bool shortForm = false)
        {
            var res = new StringBuilder();

            for (int rank = 0; rank < Constants.BoardRanks; rank++)
            {
                int gap = 0;
                for (int file = 0; file < Constants.BoardFiles; file++)
                {
                    var piece = position[rank * Constants.BoardFiles + file];
                    if (piece != Piece.None)
                    {
                        if (gap > 0)
                        {
                            res.Append(gap);
                            gap = 0;
                        }

                        char pieceChar = NotationHelper.GetPieceChar(piece);
                        res.Append(pieceChar);
                    }
                    else
                    {
                        gap++;
                    }
                }
                res.Append(gap > 0 ? gap.ToString() : string.Empty);
                if (rank < 7)
                {
                    res.Append('/');
                }
            }

            res.Append($" {(position.WhiteToMove ? 'w' : 'b')}");

            if (position.CurrentState[0] != Castling.None || position.CurrentState[1] != Castling.None)
            {
                res.Append(' ');
                res.Append(NotationHelper.GetCastlingOptionsString(position.CurrentState[0], position.IsChess960, position.Pieces[0].Rooks, position.Pieces[0].King).ToUpper());
                res.Append(NotationHelper.GetCastlingOptionsString(position.CurrentState[1], position.IsChess960, position.Pieces[1].Rooks, position.Pieces[1].King));
            }
            else
            {
                res.Append(" -");
            }

            if (position.CurrentState.EnPassantSquare > 0)
            {
                res.Append($" {NotationHelper.GetSquareString(position.CurrentState.EnPassantSquare)}");
            }
            else
            {
                res.Append(" -");
            }

            if (!shortForm)
            {
                res.Append($" {position.CurrentState.HalfMoveClock}");
                res.Append($" {position.TotalMoves}");
            }

            return(res.ToString());
        }
Beispiel #19
0
 public void InvalidsquareStringParsedTosquareIdThrows(string squareString)
 {
     Assert.Throws <ArgumentException>(() => NotationHelper.ParseSquare(squareString));
 }
Beispiel #20
0
 public override string ToString()
 {
     return(NotationHelper.GetMoveCode(this));
 }
Beispiel #21
0
 public void InvalidMoveCodesParseThrows(string moveCode)
 {
     Assert.Throws <ArgumentException>(() => NotationHelper.ParseMoveCode(moveCode));
 }