Beispiel #1
0
    private void Awake()
    {
        m_match = new Match();

        switch (m_matchControlType)
        {
        case MatchControlType.Local:
        {
            var userInput = new MouseAndKbInput();
            m_matchCtrl = new LocalMatchController(m_match, userInput);
            m_matchView.Init(m_match);
            break;
        }

        case MatchControlType.Client:
        {
            m_match.SetLogic(new ClientMatchLogic(m_match));
            m_matchCtrl = ClientBuilder.Create(m_match, m_matchView);
            break;
        }

        case MatchControlType.Server:
        {
            m_match.SetLogic(new ServerMatchLogic(m_match));
            m_matchCtrl = ServerBuilder.Create(m_match);
            m_matchView.Init(m_match);
            break;
        }
        }
    }
        public void GetHashCode_WhenTwoDifferentInstancesAreCreated_ThenInstanceHashCodesAreNotEqual()
        {
            // arrange
            ServerBuilder builder = ServerBuilder.Create()
                                    .WithConnectionsAllowed(true)
                                    .WithHostname("server.domain.local")
                                    .WithIP("127.0.0.1")
                                    .WithLocation("location")
                                    .WithMaximumConnections(250)
                                    .WithName("name");

            ServerBuilder builder1 = ServerBuilder.Create()
                                     .WithConnectionsAllowed(true)
                                     .WithHostname("server.domain.local1")
                                     .WithIP("127.0.0.11")
                                     .WithLocation("location1")
                                     .WithMaximumConnections(250)
                                     .WithName("name1");

            Server instance0 = builder.Build();
            Server instance1 = builder1.Build();

            // act
            int result0 = instance0.GetHashCode();
            int result1 = instance1.GetHashCode();

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(Equals(result0, result1), Is.False);
        }
        public void GetHashCode_WhenInstanceIsDeseraializeAndSerializedBack_ThenInstancesHashCodesAreEqual()
        {
            // arrange
            ServerBuilder builder = ServerBuilder.Create()
                                    .WithConnectionsAllowed(true)
                                    .WithHostname("server.domain.local")
                                    .WithIP("127.0.0.1")
                                    .WithLocation("location")
                                    .WithMaximumConnections(250)
                                    .WithName("name");

            Server instance0 = builder.Build();

            string serializedText = instance0.Serialize();

            Server instance1 = serializedText.Deserialize <Server>();

            // act
            int result0 = instance0.GetHashCode();
            int result1 = instance1.GetHashCode();

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(Equals(result0, result1), Is.True);
        }
        public void Clone_WhenInstanceCloned_ThenInstancesAreEqual()
        {
            // arrange
            ServerBuilder builder = ServerBuilder.Create()
                                    .WithConnectionsAllowed(true)
                                    .WithHostname("server.domain.local")
                                    .WithIP("127.0.0.1")
                                    .WithLocation("location")
                                    .WithMaximumConnections(250)
                                    .WithName("name");

            Server instance0 = builder.Build();

            object instance1 = instance0.Clone();

            // act
            bool result = Equals(instance0, instance1);

            // assert
            Assert.That(instance0, Is.Not.Null);
            Assert.That(instance1, Is.Not.Null);
            Assert.That(instance1, Is.InstanceOf <Server>());
            Assert.That(ReferenceEquals(instance0, instance1), Is.Not.True);
            Assert.That(result, Is.True);
        }
Beispiel #5
0
        protected override Server CreateItem(string data)
        {
            if (string.IsNullOrWhiteSpace(data))
            {
                return(null);
            }

            string[] dataItems = Split(data);

            if (dataItems.Length == 0)
            {
                return(null);
            }

            return(ServerBuilder.Create()
                   .WithHostname(dataItems[ServerIndex.Hostname])
                   .WithIP(dataItems[ServerIndex.IP])
                   .WithLocation(dataItems[ServerIndex.Location])
                   .WithName(dataItems[ServerIndex.Name])
                   .WithConnectionsAllowed(Convert.ToBoolean(Convert.ToInt16(dataItems[ServerIndex.ConnectionsAllowed])))
                   .WithMaximumConnections(int.Parse(dataItems[ServerIndex.MaximumConnections]))
                   .Build());
        }