コード例 #1
0
    // Start is called before the first frame update
    void Start()
    {
        DigitObserver         observer  = new DigitObserver();
        GraphObserver         observer1 = new GraphObserver();
        RandomNumberGenerator generator = new RandomNumberGenerator();

        generator.AddObserver(observer);
        generator.AddObserver(observer1);
        generator.Generate();
    }
コード例 #2
0
    public static void Main(string[] args)
    {
        NumberGenerator generator = new RandomNumberGenerator();
        Observer        observer1 = new DigitObserver();
        Observer        observer2 = new GraphObserver();

        generator.AddObserver(observer1);
        generator.AddObserver(observer2);

        generator.Execute();
    }
コード例 #3
0
        public void NumberGenerator_Notify_SendAlert()
        {
            var             digitMock   = new Mock <DigitObserver>();
            NumberGenerator argInstance = null;

            digitMock.Setup(x => x.Update(It.IsAny <NumberGenerator>())).Callback <NumberGenerator>(sm => argInstance = sm);

            var graphMock = new Mock <GraphObserver>();

            graphMock.Setup(x => x.Update(It.IsAny <NumberGenerator>()));

            var generator = new RandomNumberGenerator();

            generator.AddObserver(digitMock.Object);
            generator.AddObserver(graphMock.Object);
            generator.NotifyObservers();

            digitMock.Verify(x => x.Update(generator), Times.Once);
            Assert.Same(argInstance, generator);
            graphMock.Verify(x => x.Update(generator), Times.Once);
        }