Exemplo n.º 1
0
        public void Receive_WhenPassedNull_ThrowsArgumentNullException()
        {
            var contract = StatefulObject.Create <FavoriteNumberContract>(new Dictionary <string, object>());
            var receiver = contract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(this.addressFactory.CreateAddress()));

            Assert.Throws <ArgumentNullException>(() => receiver.Invoke(null));
        }
        public static StatefulObject DeserializeStatefulObject(byte[] serialized)
        {
            var dictionary = StateSerialization.DeserializeState(serialized);

            var type  = Type.GetType(dictionary.Get <string>("Type"));
            var state = dictionary.Get <IDictionary <string, object> >("State");

            return(StatefulObject.Create(type, state, true));
        }
Exemplo n.º 3
0
            public ContractRegistry LoadContractRegistry()
            {
                var data = this.LoadData(this.integration.contractRegistryAddress);

                this.integration.logger.LogTrace("Received registry data: " + data.Length + " bytes");

                if (data.Length == 0)
                {
                    return(new ContractRegistry());
                }

                return(StatefulObject.Create <ContractRegistry>(
                           StateSerialization.DeserializeState(data)));
            }
Exemplo n.º 4
0
        public void Receive_WhenReceivedSupportedAction_ReturnsTrue()
        {
            var contract = StatefulObject.Create <FavoriteNumberContract>(new Dictionary <string, object>()
            {
                { "User", null }
            });
            var receiver = contract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(this.addressFactory.CreateAddress()));

            receiver.Invoke(new Message(
                                contract.Address,
                                contract.Address,
                                contract.Address,
                                SetFavoriteNumberAction.Type,
                                new Dictionary <string, object>()
            {
                { SetFavoriteNumberAction.Number, 0 },
            }));
        }
        public void Serializes_And_Deserializes_Contracts()
        {
            var address      = new Address(new byte[] { 10, 20, 127, 54, 51 });
            var adminAddress = new Address(new byte[] { 10, 20, 4 });
            var contract     = StatefulObject.Create <FavoriteNumberContract>(new Dictionary <string, object> {
                { "Admin", adminAddress.ToString() }, { "Number", 15 }
            });

            contract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(address));

            var serializedContract = StrongForceSerialization.SerializeStatefulObject(contract);

            var deserializedContract = (FavoriteNumberContract)StrongForceSerialization.DeserializeStatefulObject(serializedContract);

            deserializedContract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(address));

            Assert.Equal(contract.GetState(), deserializedContract.GetState());
            Assert.Equal(contract.Address, deserializedContract.Address);
            Assert.Equal(contract.Number, deserializedContract.Number);
        }
Exemplo n.º 6
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            var initialKit = (KitContract)StatefulObject.Create(
                this.settings.InitialKitType,
                this.settings.InitialKitPayload);

            initialKit.RegisterWithRegistry(
                new InMemoryIntegration.FakeContractContext(
                    KitContract.DefaultAddress));

            var facade = new CosmosIntegration(
                this.logger,
                StrongForceSerialization.SerializeStatefulObject(initialKit));

            this.server = new Server
            {
                Services = { Strongforce.StrongForce.BindService(facade) },
                Ports    = { new ServerPort(this.settings.Hostname, this.settings.Port, ServerCredentials.Insecure) },
            };
            this.server.Start();
            return(Task.CompletedTask);
        }
        public void Receive_WhenPassedSetFavoriteNumberAction_SetsNumberCorrectly()
        {
            const int expectedNumber = 32;

            var contract = StatefulObject.Create <FavoriteNumberContract>(new Dictionary <string, object>()
            {
                { "User", null }
            });
            var receiver = contract.RegisterWithRegistry(new InMemoryIntegration.FakeContractContext(this.addressFactory.CreateAddress()));

            var action = new Message(
                contract.Address,
                contract.Address,
                contract.Address,
                SetFavoriteNumberAction.Type,
                new Dictionary <string, object>()
            {
                { SetFavoriteNumberAction.Number, expectedNumber },
            });

            receiver.Invoke(action);

            Assert.Equal(expectedNumber, ((FavoriteNumberContract)contract).Number);
        }