/// <summary>
        /// C'tor creates a fakeTwinHelper
        /// The constructor parses the twin from the file path
        /// and sets the clientMock with this twin
        /// </summary>
        /// <param name="clientMock">A ModuleClient mock</param>
        /// <param name="path">Path to a serialized twin json file</param>
        public FakeTwinHelper(ModuleClientMock clientMock, string path)
        {
            _twin = GetTwinFromFile(path);
            _agentConfiguration = _twin.Properties.Desired["ms_iotn:urn_azureiot_Security_SecurityAgentConfiguration"];
            _clientMock         = clientMock;
            _clientMock.Reset(_twin);

            UpdateAgentTwinConfiguration();
        }
        /// <summary>
        /// C'tor creates a fakeTwinHelper
        /// The constructor parses the twin from the file path
        /// and sets the clientMock with this twin
        /// </summary>
        /// <param name="clientMock">A ModuleClient mock</param>
        /// <param name="path">Path to a serialized twin json file</param>
        public FakeTwinHelper(ModuleClientMock clientMock, string path)
        {
            _twin = GetTwinFromFile(path);
            _agentConfiguration = _twin.Properties.Desired[IoTHubTwinConfigurationProvider <TestIotConfiguration> .ConfigSectionName];
            _clientMock         = clientMock;
            _clientMock.Reset(_twin);

            UpdateAgentTwinConfiguration();
        }
Пример #3
0
        public virtual void Init()
        {
            //Reset all fake event generators to produce empty events
            FakeOperationalEventGenerator.SetEvents(new List <FakeOperationalEvent>());
            FakeSnapshotEventGenerator.SetEvents(new List <FakePeriodicEvent>());
            FakeTriggeredEventGenerator.SetEvents(new List <FakeTriggeredEvent>());

            //Create a new twin and iot hub client
            FakesEventsFactory = new FakeEventsFactory();
            ClientMock         = (ModuleClientMock)ModuleClientProvider.GetClient();
            Twin = new FakeTwinHelper(ClientMock);
        }
        /// <summary>
        /// Heuristically waits until all of the async send-message operations are complete
        /// </summary>
        /// <param name="module">The client module which is used to send the messages</param>
        /// <returns>true if the sends were completed within the alloted time; false if otherwise</returns>
        public static bool WaitUntilAsyncMessageSendsComplete(ModuleClientMock module)
        {
            bool completed = Task.Run(async() =>
            {
                int lastSentMessages = 0;
                while (lastSentMessages < module.GetMessages().Count)
                {
                    lastSentMessages = module.GetMessages().Count;
                    await Task.Delay(TimeSpan.FromSeconds(1));
                }
            })
                             .Wait(TimeSpan.FromMinutes(1));

            return(completed);
        }
 /// <summary>
 /// C'tor creates a fakeTwinHelper
 /// The constructor sets the clientMock with an empty twin
 /// </summary>
 /// <param name="clientMock">A ModuleClient mock</param>
 public FakeTwinHelper(ModuleClientMock clientMock) : this(clientMock, DEFAULT_TWIN_PATH)
 {
 }