Esempio n. 1
0
    public void CreationTestsSimplePasses()
    {
        var userId = new EntityId(1, 1);

        DevCore.Init(userId);

        var user   = DevCore.DevInstance.simulationInstances[userId].core as ClientCoreProxy;
        var server = DevCore.DevInstance.simulationInstances[userId.FullServerId].core as ServerCoreProxy;


        Entity.globalCommands.OverwriteCommand <CreateTestCommand>();


        var res = user.CreateEntity <CreateTestCommand>();

        // the resource should now exist both on the client and server instance

        var resource = user.EntityManager.GetEntity <TestResource>(res.Id);


        // is the right type
        Assert.IsTrue(resource is TestResource);
        // has a nonlocal serverId
        Assert.IsTrue(resource.Id.ServerId != 0);
        // exists on the server
        Assert.IsTrue(server.EntityManager.Exists(resource.Id));
    }
Esempio n. 2
0
    public void FirstStartupStoreValue()
    {
        FirstStartSetupController.Instance.RedoSetup(true);
        PrivacyService.Instance.privacyScreen = new AcceptAllScreen();
        var serverId = new EntityId(1, 1, 1, 0);

        DevCore.Init(serverId, true);

        Logger.Log(ConfigController.UserSettings.userId);

        var valueToStore = "abc123Hellou :D";

        // sometimes it comes to errors when the test is run alone and the static constructor
        // of CoflnetUser didn't register the SetUserKeyValue Command

        var data = CommandData.CreateCommandData <SetUserKeyValue, KeyValuePair <string, string> > (
            ConfigController.ActiveUserId,
            new KeyValuePair <string, string> ("mykey", valueToStore));

        data.SenderId = ConfigController.ActiveUserId;
        CoflnetCore.Instance
        .SendCommand(data);

        foreach (var item in DevCore.DevInstance.simulationInstances.Keys)
        {
            Logger.Log($"having {item}");
        }

        CoflnetCore.Instance.SendCommand <GetUserKeyValue, string> (ConfigController.ActiveUserId, "mykey", ConfigController.ActiveUserId, (d) => {
            Assert.AreEqual(valueToStore, d.GetAs <string>());
        });
    }
Esempio n. 3
0
    public void CreationTestsWithOptions()
    {
        var testValue = 50;

        var userId = new EntityId(1, 1);

        DevCore.Init(userId);

        var user = DevCore.DevInstance.simulationInstances[userId].core as ClientCoreProxy;


        Entity.globalCommands.OverwriteCommand <CreateTestWithOptionsCommand>();


        var res = user.CreateEntity <CreateTestWithOptionsCommand, CreateTestWithOptionsCommand.Options>(
            new CreateTestWithOptionsCommand.Options()
        {
            Value = testValue
        });

        // the resource should now exist both on the client and server instance

        var resource = user.EntityManager.GetEntity <TestResource>(res.Id);


        Assert.AreEqual(testValue, resource.value);
    }
Esempio n. 4
0
    public void UpdatePropagationMultipleServerConnectedTest()
    {
        var aliceDeviceId = new EntityId(1, 9);
        var bobDeviceId   = new EntityId(2, 8);

        DevCore.Init(aliceDeviceId);
        // add bob  and bobs server
        DevCore.DevInstance.AddServerCore(bobDeviceId.FullServerId);
        DevCore.DevInstance.AddClientCore(bobDeviceId, true).OnMessage = m => {
            if (m.Type == "UpdateUserName")
            {
                Assert.AreEqual("bob", m.GetAs <string>());
            }
            return(true);
        };

        var alice = DevCore.DevInstance.simulationInstances[aliceDeviceId].core;

        alice.CloneAndSubscribe(bobDeviceId);

        var msg = new CommandData(bobDeviceId, 0,
                                  MessagePackSerializer.Serialize("coflnet.app"), "AddInstalledApp");

        throw new System.Exception("The next line never finishes");
        //CoflnetCore.Instance.SendCommand(msg);


        //   CommandData.CreateCommandData<UpdateUserNameCommand,string>(
        //       bobDeviceId,"bob",0,aliceDeviceId));


        // alice should now also know the new app of bob
        Assert.IsTrue(alice.EntityManager.GetEntity <Device>(bobDeviceId).InstalledApps.Contains("coflnet.app"));
    }
Esempio n. 5
0
    public void DeviceAndInstallRegister()
    {
        FirstStartSetupController.Instance.RedoSetup(true);
        var serverId = new EntityId(1, 1, 1, 0);

        // start
        DevCore.Init(serverId, false, true);
        // servercore won't receive commands
        //DevCore.DevInstance.simulationInstances[serverId].IsConnected = false;

        //var clientCore = DevCore.DevInstance.simulationInstances[serverId];

        // start the client
        ClientCore.Init();

        // Device and Installation should now exist
        Assert.AreNotEqual(default(EntityId), ConfigController.DeviceId);
        Assert.AreNotEqual(default(EntityId), ConfigController.InstallationId);

        // enable network
        DevCore.DevInstance.simulationInstances[serverId].IsConnected = true;

        // cause an update that will attempt to send offline queue

        // Device and Installation should have online ids

        Logger.Log($"DeviceId: {ConfigController.DeviceId}");
        Logger.Log($"InstallationId: {ConfigController.InstallationId}");
    }
Esempio n. 6
0
    public void CloneAndSubscribeTest()
    {
        var aliceId = new EntityId(2, 3);
        var bobId   = new EntityId(5, 0);


        DevCore.Init(aliceId, true);

        var alice       = DevCore.DevInstance.simulationInstances[aliceId].core;
        var aliceServer = DevCore.DevInstance.simulationInstances[aliceId.FullServerId].core;
        var bob         = DevCore.DevInstance.AddServerCore(bobId).core;

        var resource = new TestEntity();

        // register resource on bob
        resource.AssignId(bob.EntityManager);
        resource.specialNumber = 42;
        // authorize access to the whole server
        resource.GetAccess().Authorize(aliceId.FullServerId, AccessMode.WRITE);


        // clone it
        alice.CloneAndSubscribe(resource.Id);



        // send (execute) command
        bob.SendCommand <SimpleTestCommand, short>(resource.Id, 0);

        // assert that update was distributed
        Assert.AreEqual(43, aliceServer.EntityManager.GetEntity <TestEntity>(resource.Id).specialNumber);
        Assert.AreEqual(43, alice.EntityManager.GetEntity <TestEntity>(resource.Id).specialNumber);
    }
Esempio n. 7
0
    public void CloningTestSimplePasses()
    {
        var aliceId = new EntityId(2, 3);
        var bobId   = new EntityId(5, 0);


        DevCore.Init(aliceId, true);



        var alice = DevCore.DevInstance.simulationInstances[aliceId.FullServerId].core;
        var bob   = DevCore.DevInstance.AddServerCore(bobId).core;


        var resource = new TestEntity();

        // register resource on Server2
        resource.AssignId(bob.EntityManager);
        resource.specialNumber = 42;
        // authorize access
        resource.GetAccess().Authorize(aliceId);

        // make sure the resource is there
        Assert.AreEqual(resource.specialNumber,
                        bob.EntityManager.GetEntity <TestEntity>(resource.Id).specialNumber);


        // clone the resource to server1
        alice.EntityManager.CloneEntity(resource.Id, res => {
            Assert.AreEqual(42, (res as TestEntity).specialNumber);
        });
    }
Esempio n. 8
0
    public void CloningCommandBufferTest()
    {
        var aliceId = new EntityId(2, 3);
        var bobId   = new EntityId(5, 0);


        DevCore.Init(aliceId, true);

        var alice = DevCore.DevInstance.simulationInstances[aliceId.FullServerId].core;
        var bob   = DevCore.DevInstance.AddServerCore(bobId).core;

        var resource = new TestEntity();

        // register resource on Server2
        resource.AssignId(bob.EntityManager);
        resource.specialNumber = 42;
        // authorize access to the whole server
        resource.GetAccess().Authorize(aliceId.FullServerId);

        // send command
        alice.SendCommand <SimpleTestCommand, short>(resource.Id, 0);


        bool calbackExecuted = false;

        // clone the resource to server1
        alice.EntityManager.CloneEntity(resource.Id, res => {
            calbackExecuted = true;
            Assert.AreEqual(43, (res as TestEntity).specialNumber);
            calbackExecuted = true;
        });

        // the devsocket always executes callback bevore continuing if no exception occured
        Assert.IsTrue(calbackExecuted);
    }
Esempio n. 9
0
    public void MessageDeliveryMultipleServerConnectedTest()
    {
        var alice = new EntityId(1, 123);
        var bob   = new EntityId(2, 555);

        DevCore.Init(alice);
        DevCore.DevInstance.AddClientCore(bob).OnMessage = m => {
            // when bob receives the message make sure it is valid
            Assert.AreEqual("msg", m.Type);
            return(false);
        };

        CoflnetCore.Instance.SendCommand(
            CommandData.CreateCommandData <ChatMessageCommand, string>(
                bob, "hi", 0, alice));
    }
Esempio n. 10
0
    public void MessageDeliverySameServerConnectedTest()
    {
        var alice = new EntityId(1, 123);
        var bob   = new EntityId(1, 555);

        DevCore.Init(alice);


        DevCore.DevInstance.AddClientCore(bob).OnMessage = m => {
            // received data is of type msg
            Assert.AreEqual("msg", m.Type);
            return(false);
        };


        CoflnetCore.Instance.SendCommand(
            CommandData.CreateCommandData <ChatMessageCommand, string>(
                bob, "hi", 0, alice));
    }
Esempio n. 11
0
    public void FirstStartupRegisterLoginTest()
    {
        PrivacyService.Instance.privacyScreen = new AcceptAllScreen();
        var serverId = new EntityId(1, 1, 1, 0);

        DevCore.Init(serverId, true);



        Logger.Log("The new user has the id: " + UserService.Instance.CurrentUserId);
        Logger.Log($"The Active user is: {ConfigController.ActiveUserId}");
        // userid exists client side
        Assert.NotNull(UserService.Instance.CurrentUser);

        // exists server side
        CoflnetUser user;

        // ActiveUserId should change on first register
        DevCore.DevInstance
        .simulationInstances[serverId]
        .core.EntityManager
        .TryGetEntity <CoflnetUser> (ConfigController.ActiveUserId, out user);

        Assert.NotNull(user);


        // exists client side
        CoflnetUser userOnClient;

        // ActiveUserId should change on first register
        DevCore.DevInstance
        .simulationInstances[serverId]
        .core.EntityManager
        .TryGetEntity <CoflnetUser> (ConfigController.ActiveUserId, out userOnClient);

        Assert.NotNull(userOnClient);


        FirstStartSetupController.Instance.RedoSetup(true);
    }
Esempio n. 12
0
 public void SmokeTestsSimplePasses()
 {
     DevCore.Init(new Coflnet.EntityId(1, 1, 1, 123456));
 }
Esempio n. 13
0
    public void ClientServerSimulation()
    {
        DevCore.Init(new Coflnet.EntityId(1, 1, 1, 123456));

        // DevCore.Instance.SendCommand()
    }
Esempio n. 14
0
 public void FirstStartupTestSimplePasses()
 {
     DevCore.Init(new EntityId(1, 1, 1, 123456));
 }