/// <summary> /// Implementation of the test itself. /// </summary> /// <returns>true if the test passes, false otherwise.</returns> public override async Task <bool> RunAsync() { IPAddress ServerIp = (IPAddress)ArgumentValues["Server IP"]; int PrimaryPort = (int)ArgumentValues["primary Port"]; int BasePort = (int)ArgumentValues["Base Port"]; int LocPort = (int)ArgumentValues["LOC Port"]; log.Trace("(ServerIp:'{0}',PrimaryPort:{1},BasePort:{2},LocPort:{3})", ServerIp, PrimaryPort, BasePort, LocPort); bool res = false; Passed = false; ProtocolClient client = new ProtocolClient(); ProfileServer profileServer = null; LocServer locServer = null; try { MessageBuilder mb = client.MessageBuilder; // Step 1 log.Trace("Step 1"); // Get port list. await client.ConnectAsync(ServerIp, PrimaryPort, false); Dictionary <ServerRoleType, uint> rolePorts = new Dictionary <ServerRoleType, uint>(); bool listPortsOk = await client.ListServerPorts(rolePorts); client.CloseConnection(); // Create identities. ProfilePublicKeys = new List <byte[]>(); for (int i = 0; i < ProfileNames.Count; i++) { ProtocolClient protocolClient = new ProtocolClient(); ProfilePublicKeys.Add(protocolClient.GetIdentityKeys().PublicKey); protocolClient.Dispose(); } // Start simulated profile server. profileServer = new ProfileServer("TestProfileServer", ServerIp, BasePort, client.GetIdentityKeys(), new GpsLocation(1, 2)); bool profileServerStartOk = profileServer.Start(); // Start simulated LOC server. locServer = new LocServer("TestLocServer", ServerIp, LocPort); bool locServerStartOk = locServer.Start(); await locServer.WaitForProfileServerConnectionAsync(); bool step1Ok = profileServerStartOk && locServerStartOk; log.Trace("Step 1: {0}", step1Ok ? "PASSED" : "FAILED"); // Step 2 log.Trace("Step 2"); // Initialize the original set of update messages update. List <SharedProfileUpdateItem> originalUpdateItems = new List <SharedProfileUpdateItem>(); for (int i = 0; i < ProfileNames.Count; i++) { SharedProfileUpdateItem updateItem = new SharedProfileUpdateItem() { Add = new SharedProfileAddItem() { Version = SemVer.V100.ToByteString(), Name = ProfileNames[i], Type = ProfileTypes[i], ExtraData = ProfileExtraData[i] != null ? ProfileExtraData[i] : "", Latitude = ProfileLocations[i].GetLocationTypeLatitude(), Longitude = ProfileLocations[i].GetLocationTypeLongitude(), IdentityPublicKey = ProtocolHelper.ByteArrayToByteString(ProfilePublicKeys[i]), SetThumbnailImage = ProfileImages[i] != null, ThumbnailImage = ProtocolHelper.ByteArrayToByteString(ProfileImages[i] != null ? File.ReadAllBytes(ProfileImages[i]) : new byte[0]) } }; originalUpdateItems.Add(updateItem); } List <SharedProfileUpdateItem> updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Version = ProtocolHelper.ByteArrayToByteString(new byte[] { 1, 0 }); bool initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.version"); bool step2Ok = initOk; log.Trace("Step 2: {0}", step2Ok ? "PASSED" : "FAILED"); // Step 3 log.Trace("Step 3"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Version = ProtocolHelper.ByteArrayToByteString(new byte[] { 0, 0, 0 }); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.version"); bool step3Ok = initOk; log.Trace("Step 3: {0}", step3Ok ? "PASSED" : "FAILED"); // Step 4 log.Trace("Step 4"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.IdentityPublicKey = ProtocolHelper.ByteArrayToByteString(Encoding.UTF8.GetBytes(new string ('a', 300))); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.identityPublicKey"); bool step4Ok = initOk; log.Trace("Step 4: {0}", step4Ok ? "PASSED" : "FAILED"); // Step 5 log.Trace("Step 5"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.IdentityPublicKey = updateItems[0].Add.IdentityPublicKey; initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.identityPublicKey"); bool step5Ok = initOk; log.Trace("Step 5: {0}", step5Ok ? "PASSED" : "FAILED"); // Step 6 log.Trace("Step 6"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Name = new string('a', 70); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.name"); bool step6Ok = initOk; log.Trace("Step 6: {0}", step6Ok ? "PASSED" : "FAILED"); // Step 7 log.Trace("Step 7"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Name = new string('ɐ', 50); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.name"); bool step7Ok = initOk; log.Trace("Step 7: {0}", step7Ok ? "PASSED" : "FAILED"); // Step 8 log.Trace("Step 8"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Type = new string('a', 70); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.type"); bool step8Ok = initOk; log.Trace("Step 8: {0}", step8Ok ? "PASSED" : "FAILED"); // Step 9 log.Trace("Step 9"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Type = new string('ɐ', 50); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.type"); bool step9Ok = initOk; log.Trace("Step 9: {0}", step9Ok ? "PASSED" : "FAILED"); // Step 10 log.Trace("Step 10"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Type = ""; initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.type"); bool step10Ok = initOk; log.Trace("Step 10: {0}", step10Ok ? "PASSED" : "FAILED"); // Step 11 log.Trace("Step 11"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.SetThumbnailImage = true; updateItems[2].Add.ThumbnailImage = ProtocolHelper.ByteArrayToByteString(new byte[0]); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.thumbnailImage"); bool step11Ok = initOk; log.Trace("Step 11: {0}", step11Ok ? "PASSED" : "FAILED"); // Step 12 log.Trace("Step 12"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.SetThumbnailImage = true; updateItems[2].Add.ThumbnailImage = ProtocolHelper.ByteArrayToByteString(new byte[] { 0, 1, 2 }); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.thumbnailImage"); bool step12Ok = initOk; log.Trace("Step 12: {0}", step12Ok ? "PASSED" : "FAILED"); // Step 13 log.Trace("Step 13"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Latitude = 987654321; initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.latitude"); bool step13Ok = initOk; log.Trace("Step 13: {0}", step13Ok ? "PASSED" : "FAILED"); // Step 14 log.Trace("Step 14"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Longitude = 987654321; initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.longitude"); bool step14Ok = initOk; log.Trace("Step 14: {0}", step14Ok ? "PASSED" : "FAILED"); // Step 15 log.Trace("Step 15"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.ExtraData = new string('a', 270); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.extraData"); bool step15Ok = initOk; log.Trace("Step 15: {0}", step15Ok ? "PASSED" : "FAILED"); // Step 16 log.Trace("Step 16"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.ExtraData = new string('ɐ', 150); initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.extraData"); bool step16Ok = initOk; log.Trace("Step 16: {0}", step16Ok ? "PASSED" : "FAILED"); // Step 17 log.Trace("Step 17"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem() { Change = new SharedProfileChangeItem() { IdentityNetworkId = ProtocolHelper.ByteArrayToByteString(Crypto.Sha256(updateItems[0].Add.IdentityPublicKey.ToByteArray())) } }; initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.actionType"); bool step17Ok = initOk; log.Trace("Step 17: {0}", step17Ok ? "PASSED" : "FAILED"); // Step 18 log.Trace("Step 18"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem() { Delete = new SharedProfileDeleteItem() { IdentityNetworkId = ProtocolHelper.ByteArrayToByteString(Crypto.Sha256(updateItems[0].Add.IdentityPublicKey.ToByteArray())) } }; initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.actionType"); bool step18Ok = initOk; log.Trace("Step 18: {0}", step18Ok ? "PASSED" : "FAILED"); // Step 19 log.Trace("Step 19"); updateItems = new List <SharedProfileUpdateItem>(originalUpdateItems); updateItems[2] = new SharedProfileUpdateItem(updateItems[2]); updateItems[2].Add.Name = ""; initOk = await PerformInitializationProcessWithUpdateItemsAsync(updateItems, profileServer, locServer, "2.add.name"); bool step19Ok = initOk; log.Trace("Step 19: {0}", step19Ok ? "PASSED" : "FAILED"); Passed = step1Ok && step2Ok && step3Ok && step4Ok && step5Ok && step6Ok && step7Ok && step8Ok && step9Ok && step10Ok && step11Ok && step12Ok && step13Ok && step14Ok && step15Ok && step16Ok && step17Ok && step18Ok && step19Ok; res = true; } catch (Exception e) { log.Error("Exception occurred: {0}", e.ToString()); } client.Dispose(); if (profileServer != null) { profileServer.Shutdown(); } if (locServer != null) { locServer.Shutdown(); } log.Trace("(-):{0}", res); return(res); }