public void CreateInstanceUpdateMessagesWorksForManyInstances()
        {
            int numberInstances = (4 * UpdateInstances.MaximumInstanceChunkSize) + 7;
            var messages        = UpdateInstances.CreateInstanceUpdateMessages(UpdateInstancesTest.CreateInstances(numberInstances)).ToList();

            Assert.True(
                7 == messages.Count,
                "There should be seven messages: One to clear old instances, five to add new ones, and one to complete the instance update.");
            Assert.True(messages[0] is ClearInstances, "The first message should clear old instances.");

            for (int i = 1; i <= 4; i++)
            {
                Assert.True(messages[i] is AddInstances <TestInstance>, $"The {i}th message should add new instances.");
                UpdateInstancesTest.CheckAddMessageContainsCorrectInstances(
                    (AddInstances <TestInstance>)messages[i],
                    firstInstanceIdentifier: (i - 1) * UpdateInstances.MaximumInstanceChunkSize,
                    numberInstances: UpdateInstances.MaximumInstanceChunkSize);
            }

            Assert.True(
                messages[5] is AddInstances <TestInstance>,
                "The fifth message should add the remaining instances.");
            UpdateInstancesTest.CheckAddMessageContainsCorrectInstances(
                (AddInstances <TestInstance>)messages[5],
                firstInstanceIdentifier: 4 * UpdateInstances.MaximumInstanceChunkSize,
                numberInstances: 7);

            Assert.True(messages[6] is InstanceUpdateFinished, "The seventh message should complete the update process.");
        }
        public void CreateInstanceUpdateMessagesWorksForFewInstances()
        {
            var messages = UpdateInstances.CreateInstanceUpdateMessages(UpdateInstancesTest.CreateInstances(number: 2)).ToList();

            Assert.True(
                3 == messages.Count,
                "There should be two messages: One to clear old instances, one to add new ones, and one to complete the instance update.");
            Assert.True(messages[0] is ClearInstances, "The first message should clear old instances.");
            Assert.True(messages[1] is AddInstances <TestInstance>, "The second message should add new instances.");
            Assert.True(messages[2] is InstanceUpdateFinished, "The third message should complete the update process.");

            UpdateInstancesTest.CheckAddMessageContainsCorrectInstances(
                (AddInstances <TestInstance>)messages[1],
                firstInstanceIdentifier: 0,
                numberInstances: 2);
        }
        public void CreateInstanceUpdateMessagesWorksForEdgeCases()
        {
            int numberInstances = 2 * UpdateInstances.MaximumInstanceChunkSize;
            var messages        = UpdateInstances.CreateInstanceUpdateMessages(UpdateInstancesTest.CreateInstances(numberInstances)).ToList();

            Assert.True(
                4 == messages.Count,
                "There should be four messages: One to clear old instances, two to add new ones, and one to complete the instance update.");
            Assert.True(messages[0] is ClearInstances, "The first message should clear old instances.");

            for (int i = 1; i <= 2; i++)
            {
                Assert.True(messages[i] is AddInstances <TestInstance>, $"The {i}th message should add new instances.");
                UpdateInstancesTest.CheckAddMessageContainsCorrectInstances(
                    (AddInstances <TestInstance>)messages[i],
                    firstInstanceIdentifier: (i - 1) * UpdateInstances.MaximumInstanceChunkSize,
                    numberInstances: UpdateInstances.MaximumInstanceChunkSize);
            }

            Assert.True(messages[3] is InstanceUpdateFinished, "The fourth message should complete the update process.");
        }