Exemplo n.º 1
0
        public async Task CheckRollsAreRemovedCorrectly()
        {
            var checkRoll1 = new GreigeRoll {
                RollNo = "CHKROL"
            };
            var checkRoll2 = new GreigeRoll {
                RollNo = "CHKROL"
            };
            var newRolls1 = (IEnumerable <GreigeRoll>) this.Clone(this.roll1, checkRoll1, this.roll2, checkRoll2, this.roll3).ToArray();
            var expected  = newRolls1;

            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(true);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls1);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);
            await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

            Assert.True(this.target.Rolls.SequenceEqual(expected, this));

            do
            {
                // Update with newRolls1; remove one roll each time
                expected = newRolls1 = newRolls1.Skip(1);
                this.dbMfg.ClearReceivedCalls();
                this.dbMfg.GetIsSewinQueueChangedAsync(this.target.Rolls.Count, this.target.Rolls.First().RollNo, this.target.Rolls.Last().RollNo).Returns(true);
                this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls1);
                this.scheduler.AdvanceBy(SewinQueue.RefreshInterval.Ticks);
                await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

                // Verify the updated queue
                Assert.True(this.target.Rolls.SequenceEqual(expected, this));
            }while (newRolls1.Any());
        }
Exemplo n.º 2
0
        public async Task RollsStillInUseAreNotRemoved()
        {
            var newRolls1 = this.Clone(this.roll1, this.roll2, this.roll3).ToArray();
            var newRolls2 = this.Clone(this.roll3, this.roll4, this.roll5).ToArray();
            var expected  = new GreigeRoll[] { this.roll2, this.roll3, this.roll4, this.roll5 };

            // Fill the queue with newRolls1
            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(true);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls1);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);
            await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

            this.target.CanRemoveRollQuery += RollInUseHandler; // keep roll2

            // Update with newRolls2
            this.dbMfg.ClearReceivedCalls();
            this.dbMfg.GetIsSewinQueueChangedAsync(3, this.roll1.RollNo, this.roll3.RollNo).Returns(true);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls2);
            this.scheduler.AdvanceBy(SewinQueue.RefreshInterval.Ticks);
            await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

            // Verify the updated queue
            Assert.True(this.target.Rolls.SequenceEqual(expected, this));

            this.target.CanRemoveRollQuery -= RollInUseHandler;
            return;

            void RollInUseHandler(object sender, CancelEventArgs e) => e.Cancel = sender == newRolls1[1];
        }
Exemplo n.º 3
0
        public async Task MatchingRollsUpdatedNewRollsAddedOthersRemoved()
        {
            this.roll3.ProductImageURL = "Unchanged";
            var newRolls1 = new GreigeRoll[] { this.Clone(this.roll2), this.Clone(this.roll3), this.Clone(this.roll4) };

            this.roll3.ProductImageURL = "Now changed";
            var newRolls2 = new GreigeRoll[] { this.Clone(this.roll4), this.Clone(this.roll3), this.Clone(this.roll5), this.Clone(this.roll1) };
            var expected  = new GreigeRoll[] { this.Clone(this.roll3), this.Clone(this.roll4), this.Clone(this.roll5), this.Clone(this.roll1) };

            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(true);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls1);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);
            await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

            Assert.True(this.target.Rolls.SequenceEqual(newRolls1));

            this.dbMfg.ClearReceivedCalls();
            this.dbMfg.GetIsSewinQueueChangedAsync(3, this.roll2.RollNo, this.roll4.RollNo).Returns(true);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls2);
            this.scheduler.AdvanceBy(SewinQueue.RefreshInterval.Ticks);
            await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

            Assert.True(this.target.Rolls.SequenceEqual(expected, this));
            Assert.Equal("Now changed", this.target.Rolls.Single(item => item.RollNo == this.roll3.RollNo).ProductImageURL);
        }
Exemplo n.º 4
0
        public async Task GetCoaterSewinQueueIsCalledWhenGetIsQueChangedReturnsTrue()
        {
            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(true);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);
            await this.dbMfg.Received(1).GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty);

            await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();
        }
Exemplo n.º 5
0
        public async Task GetIsSewinQueueChangedCalledWithResultsFromPriorGetCoaterSewinQueue()
        {
            var newRolls = new GreigeRoll[] { this.roll1, this.roll2, this.roll3 };

            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(true);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);

            this.dbMfg.ClearReceivedCalls();
            this.scheduler.AdvanceBy(SewinQueue.RefreshInterval.Ticks);
            await this.dbMfg.Received(1).GetIsSewinQueueChangedAsync(3, this.roll1.RollNo, this.roll3.RollNo);
        }
Exemplo n.º 6
0
        public async Task GetIsSewinQueueChangedIsCalledPeriodically()
        {
            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(false);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);
            for (int j = 1; j < 5; j++)
            {
                this.scheduler.AdvanceBy(SewinQueue.RefreshInterval.Ticks - 1);
                await this.dbMfg.Received(j).GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty);

                this.scheduler.AdvanceBy(1);
                await this.dbMfg.Received(j + 1).GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty);
            }
        }
Exemplo n.º 7
0
        public void EmptyQueueIsPopulatedWithRecords()
        {
            var newRolls = new GreigeRoll[] { this.roll1, this.roll2, this.roll3 };

            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(true);
            this.dbLocal.GetNextGreigeRollId().Returns(1);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);
            Assert.True(newRolls.SequenceEqual(this.target.Rolls));

            for (int j = 0; j < this.target.Rolls.Count; j++)
            {
                Assert.Equal(j + 1, this.target.Rolls[j].Id);
            }
        }
Exemplo n.º 8
0
        public async Task MultipleCheckRollsCycleThroughProperly()
        {
            int nextId      = 1;
            var greigeRolls = new List <GreigeRoll>();

            for (int j = 0; j < 20; j++)
            {
                greigeRolls.Add(new GreigeRoll {
                    RollNo = nextId++.ToString()
                });
                greigeRolls.Add(new GreigeRoll {
                    RollNo = nextId++.ToString()
                });
                greigeRolls.Add(new GreigeRoll {
                    RollNo = "CHKROL"
                });
            }

            var newRolls1 = greigeRolls.Take(7);
            var expected  = newRolls1;

            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(true);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls1);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);
            await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

            Assert.True(this.target.Rolls.SequenceEqual(expected, this));

            int skipCount = 0;

            do
            {
                // Update with newRolls1; shift one roll each time
                expected = newRolls1 = newRolls1.Skip(skipCount).Take(7);
                this.dbMfg.ClearReceivedCalls();
                this.dbMfg.GetIsSewinQueueChangedAsync(this.target.Rolls.Count, this.target.Rolls.First().RollNo, this.target.Rolls.Last().RollNo).Returns(true);
                this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls1);
                this.scheduler.AdvanceBy(SewinQueue.RefreshInterval.Ticks);
                await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

                // Verify the updated queue
                Assert.True(this.target.Rolls.SequenceEqual(expected, this));
                skipCount++;
            }while (newRolls1.Any());
        }
Exemplo n.º 9
0
        public async Task SewinQueueCanHoldTwoCheckRolls()
        {
            var checkRoll1 = new GreigeRoll {
                RollNo = "CHKROL"
            };
            var checkRoll2 = new GreigeRoll {
                RollNo = "CHKROL"
            };
            var newRolls1 = this.Clone(this.roll1, checkRoll1, this.roll2, checkRoll2, this.roll3).ToArray();
            var expected  = newRolls1;

            this.dbMfg.GetIsSewinQueueChangedAsync(0, string.Empty, string.Empty).Returns(true);
            this.dbMfg.GetCoaterSewinQueueAsync().Returns(newRolls1);
            this.target = new SewinQueue(this.scheduler, this.dbLocal, this.dbMfg, this.settings, this.logger);
            await this.dbMfg.Received(1).GetCoaterSewinQueueAsync();

            Assert.True(this.target.Rolls.SequenceEqual(expected, this));
        }
Exemplo n.º 10
0
 public SewinQueueTests()
 {
     this.target = new SewinQueue();
     this.target.UpdateSewinQueue(this.ToJArray(this.GenerateRolls(100, 3)));
 }