public void WithEmpty_should_return_raise_object_with_event_args_emtpy_set()
        {
            var result = Raise.WithEmpty();

            var eventArgs = (result as IEventRaiserArguments).EventArguments;

            Assert.That(eventArgs, Is.EqualTo(EventArgs.Empty));
        }
        public void RecompileTemplateWhenSettingsChange()
        {
            manager.Update();

            A.CallTo(() => settings.TextTemplate).Returns("{{Artist}}");
            settings.SettingsUpdated += Raise.WithEmpty();

            File.ReadAllText(textFilename).Should().Be("artist");
        }
Esempio n. 3
0
        public void SwapTo_EditModeTextChanged_FunctionCalled()
        {
            var original = A.Fake <ITextBoxWrapper>();

            _editableBehaviourTextboxStrategy.SwapTo(original, false);

            original.TextChanged += Raise.WithEmpty();

            A.CallToSet(() => original.Width).MustHaveHappened();
        }
Esempio n. 4
0
        public void SubscribeToPoint_CallsStrategyOnEvent()
        {
            var point = A.Fake <IPoint>();

            _pointUpdateSubscriber.SubscribeToPoint(point);

            point.Updated += Raise.WithEmpty();

            A.CallTo(() => _pointUpdateStrategy.UpdatePointOutputChain(point)).MustHaveHappened(Repeated.Exactly.Twice);
        }
Esempio n. 5
0
        public void Should_not_fail_when_raising_event_that_has_no_registered_listeners()
        {
            // Arrange

            // Act
            var exception = Record.Exception(() => { this.foo.SomethingHappened += Raise.WithEmpty(); });

            // Assert
            exception.Should().BeNull();
        }
Esempio n. 6
0
        public void Should_not_fail_when_raising_event_that_has_no_registered_listeners()
        {
            // Arrange
            this.foo = A.Fake <IFoo>();

            // Act

            // Assert
            Assert.That(() => { foo.SomethingHappened += Raise.WithEmpty().Now; }, Throws.Nothing);
        }
Esempio n. 7
0
        public void WithEmpty_should_return_raise_object_with_event_args_empty_set()
        {
            // Arrange
            var result = Raise.WithEmpty();

            // Act
            var eventArgs = (result as IEventRaiserArguments).EventArguments;

            // Assert
            eventArgs.Should().Be(EventArgs.Empty);
        }
        public void WithEmpty()
        {
            "when raising event with empty arguments"
            .x(() => Fake.SubscribedEvent += Raise.WithEmpty());

            "it should pass the fake as sender"
            .x(() => CapturedSender.Should().BeSameAs(Fake));

            "it should pass empty event arguments"
            .x(() => CapturedArgs1.Should().Be(EventArgs.Empty));
        }
Esempio n. 9
0
        public void WithEmpty_should_return_raise_object_with_event_args_empty_set()
        {
            // Arrange
            this.foo.SomethingHappened += this.Foo_SomethingHappened;

            // Act
            this.foo.SomethingHappened += Raise.WithEmpty();

            // Assert
            this.eventArguments.Should().Be(EventArgs.Empty);
        }
        public void should_update_the_ok_button_depending_on_the_current_units_being_displayed()
        {
            A.CallTo(() => _view.HasError).Returns(false);

            A.CallTo(() => _displayUnitPresenter.CanClose).Returns(false);
            _displayUnitPresenter.StatusChanged += Raise.WithEmpty();
            _view.OkEnabled.ShouldBeFalse();

            A.CallTo(() => _displayUnitPresenter.CanClose).Returns(true);
            _displayUnitPresenter.StatusChanged += Raise.WithEmpty();
            _view.OkEnabled.ShouldBeTrue();
        }
Esempio n. 11
0
        public void UnsubscribedEvent(
            Exception exception)
        {
            "Given an event with no subscribers"
            .See(() => nameof(Fake.UnsubscribedEvent));

            "When I raise the event"
            .x(() => exception = Record.Exception(() => Fake.UnsubscribedEvent += Raise.WithEmpty()));

            "Then the call doesn't throw"
            .x(() => exception.Should().BeNull());
        }
Esempio n. 12
0
        public void Should_propagate_exception_thrown_by_event_handler()
        {
            // Arrange
            this.foo.SomethingHappened += this.Foo_SomethingHappenedThrows;

            // Act
            Action action    = () => this.foo.SomethingHappened += Raise.WithEmpty();
            var    exception = Record.Exception(action);

            // Assert
            exception.Should().BeAnExceptionOfType <NotImplementedException>()
            .And.StackTrace.Should().Contain("FakeItEasy.Tests.RaiseTests.Foo_SomethingHappenedThrows");
        }
        public static void RaisingEvent(ClassWithVirtualEvent fake, Exception exception)
        {
            "Given a fake of a class with a virtual event that calls base methods"
            .x(() => fake = A.Fake <ClassWithVirtualEvent>(o => o.CallsBaseMethods()));

            "When the event is raised on the fake"
            .x(() => exception = Record.Exception(() => fake.Event += Raise.WithEmpty()));

            "Then it throws an InvalidOperationException"
            .x(() => exception.Should()
               .BeAnExceptionOfType <InvalidOperationException>()
               .WithMessage("*The fake cannot raise the event because event subscription calls the base implementation*"));
        }
        public void SkillsUpdated_PropertyChangedInvoked()
        {
            //Arrange
            var wasCalled = false;

            _skillTableModel.PropertyChanged += (o, e) => wasCalled = true;

            //Act
            _skillsService.SkillsUpdated += Raise.WithEmpty();

            //Assert
            wasCalled.Should().BeTrue();
        }
Esempio n. 15
0
        public void WithEmpty()
        {
            "Given an event of type EventHandler"
            .See(() => nameof(Fake.SubscribedEvent));

            "When I raise the event without specifying sender or arguments"
            .x(() => Fake.SubscribedEvent += Raise.WithEmpty());

            "Then the fake is passed as the sender"
            .x(() => CapturedSender.Should().BeSameAs(Fake));

            "And an empty EventArgs is passed as the event arguments"
            .x(() => CapturedArgs1.Should().Be(EventArgs.Empty));
        }
Esempio n. 16
0
        public void When_the_timer_ticks_Change_the_desk_state()
        {
            var timer  = A.Fake <ITimer>();
            var target = new StandUpModel(timer, SittingTime, StandingTime);

            Assert.That(target.DeskState, Is.EqualTo(DeskState.Sitting));

            timer.Tick += Raise.WithEmpty().Now;

            Assert.That(target.DeskState, Is.EqualTo(DeskState.Standing));

            timer.Tick += Raise.WithEmpty().Now;

            Assert.That(target.DeskState, Is.EqualTo(DeskState.Sitting));
        }
Esempio n. 17
0
        public void Should_not_leak_handlers_when_raising()
        {
            // Arrange
            var eventHandlerArgumentProvider = ServiceLocator.Resolve <EventHandlerArgumentProviderMap>();

            this.foo.SomethingHappened += this.Foo_SomethingHappened;

            EventHandler raisingHandler = Raise.WithEmpty(); // EventHandler to force the implicit conversion

            // Act
            this.foo.SomethingHappened += raisingHandler;

            // Assert
            eventHandlerArgumentProvider.TryTakeArgumentProviderFor(raisingHandler, out _)
            .Should().BeFalse();
        }
Esempio n. 18
0
        public void When_the_authentication_state_changes_Propagate_that_event()
        {
            var authenticationService = A.Fake <IAuthenticationService>();
            var raised = false;

            var target = new StandUpViewModel(Model, authenticationService, A.Fake <IBringToForeground>());

            target.PropertyChanged += (sender, args) =>
            {
                raised = args.PropertyName.Equals("AuthenticationStatus");
            };

            authenticationService.AuthenticationStateChanged += Raise.WithEmpty();

            Assert.That(raised, Is.True);
        }
        public void RaisingInternalEvent(ClassWithInternalEventVisibleToDynamicProxy fake, EventHandler handler)
        {
            "Given a fake of a class with an internal event"
            .x(() => fake = A.Fake <ClassWithInternalEventVisibleToDynamicProxy>());

            "And a fake event handler"
            .x(() => handler = A.Fake <EventHandler>());

            "And the fake handler is subscribed to the fake's event"
            .x(() => fake.TheEvent += handler);

            "When I raise the event"
            .x(() => fake.TheEvent += Raise.WithEmpty());

            "Then the handler is called"
            .x(() => A.CallTo(handler).MustHaveHappened());
        }
Esempio n. 20
0
        public void The_current_leg_is_different_for_each_desk_state()
        {
            var timer  = A.Fake <ITimer>();
            var target = new StandUpModel(timer, SittingTime, StandingTime);

            Assert.That(target.CurrentLeg, Is.EqualTo(SittingTime));

            timer.Tick += Raise.WithEmpty().Now;
            target.NewDeskStateStarted();

            Assert.That(target.CurrentLeg, Is.EqualTo(StandingTime));

            timer.Tick += Raise.WithEmpty().Now;
            target.NewDeskStateStarted();

            Assert.That(target.CurrentLeg, Is.EqualTo(SittingTime));
        }
Esempio n. 21
0
        public static void EventsManaged(IMyInterface fake, EventHandler handler)
        {
            "Given a strict fake that manages events"
            .x(() => fake = A.Fake <IMyInterface>(options =>
                                                  options.Strict(StrictFakeOptions.AllowEvents)));

            "And an event handler"
            .x(() => handler = A.Fake <EventHandler>());

            "When the handler is subscribed to the fake's event"
            .x(() => fake.Event += handler);

            "And the event is raised using Raise"
            .x(() => fake.Event += Raise.WithEmpty());

            "Then the handler is called"
            .x(() => A.CallTo(handler).MustHaveHappened());
        }
Esempio n. 22
0
        public static void RaisingEventOnWrappingFakeUsingRaiseSyntax(Foo realObject, IFoo wrapper, EventHandler handler, Exception exception)
        {
            "Given a real object"
            .x(() => realObject = new Foo());

            "And a fake wrapping this object"
            .x(() => wrapper = A.Fake <IFoo>(o => o.Wrapping(realObject)));

            "And an event handler"
            .x(() => handler = A.Fake <EventHandler>());

            "When the event is raised on the fake using the '+= Raise' syntax"
            .x(() => exception = Record.Exception(() => wrapper.SomeEvent += Raise.WithEmpty()));

            "Then an InvalidOperationException is thrown"
            .x(() => exception.Should()
               .BeAnExceptionOfType <InvalidOperationException>()
               .WithMessage("*The fake cannot raise the event because it's a wrapping fake*"));
        }
Esempio n. 23
0
        public async Task ExecuteAsync_ShouldThrow_WhenDisposing()
        {
            // arrange
            var control = testSut.SetupControl(ExifToolArguments.BoolFalse);

            sut.Initialize();
            var disposingTask = sut.DisposeAsync();

            // act
            control.Entered.WaitOne();
            Func <Task> act = async() => _ = await sut.ExecuteAsync(null);

            // assert
            act.Should().Throw <Exception>().WithMessage("Disposing");

            control.Release.Set();
            shell.ProcessExited += Raise.WithEmpty();
            await disposingTask;
        }
Esempio n. 24
0
        public void MultipleSubscribers(
            int handler1InvocationCount,
            int handler2InvocationCount)
        {
            "establish"
            .x(() =>
            {
                Fake.SubscribedEvent += (s, e) => handler1InvocationCount++;
                Fake.SubscribedEvent += (s, e) => handler2InvocationCount++;
            });

            "when raising event with multiple subscribers"
            .x(() => Fake.SubscribedEvent += Raise.WithEmpty());

            "it should invoke the first handler once"
            .x(() => handler1InvocationCount.Should().Be(1));

            "it should invoke the second handler once"
            .x(() => handler2InvocationCount.Should().Be(1));
        }
Esempio n. 25
0
        public void ShouldAddAndRemoveHandlersFromFakeEvent()
        {
            //given
            var globalHotkey = A.Fake <GlobalHotkey>();

            var counter = 0;

            EventHandler firstHandler  = (sender, args) => counter++;
            EventHandler secondHandler = (sender, args) => counter++;

            globalHotkey.HotkeyPressed += firstHandler;
            globalHotkey.HotkeyPressed += secondHandler;
            globalHotkey.HotkeyPressed -= firstHandler;

            //when
            globalHotkey.HotkeyPressed += Raise.WithEmpty();

            //then
            Assert.That(counter, Is.EqualTo(1));
        }
Esempio n. 26
0
        public async Task ExecuteAsync_ShouldThrow_WhenDisposed()
        {
            // arrange

            // ExifToolArguments.StayOpen, ExifToolArguments.BoolFalse
            A.CallTo(() => shell.WriteLineAsync(ExifToolArguments.BoolFalse))
            .ReturnsLazily(async call =>
            {
                await Task.Yield();
                shell.ProcessExited += Raise.WithEmpty();
            });

            sut.Initialize();
            await sut.DisposeAsync();

            // act
            Func <Task> act = async() => _ = await sut.ExecuteAsync(null);

            // assert
            act.Should().Throw <Exception>().WithMessage("Disposed");
        }
Esempio n. 27
0
        public void TestConnectTimeoutCallsTimer()
        {
            WebSocketJetConnection webSocketJetConnection = new WebSocketJetConnection("ws://172.19.191.179:8081");
            ITimer     timer     = A.Fake <ITimer>();
            IWebSocket webSocket = WebSocketFakesFactory.CreateWebSocketThatFailsConnectDueTimeout(timer);

            webSocketJetConnection.SetWebSocket(webSocket);
            webSocketJetConnection.ConnectTimer = timer;

            Action <bool> connectCallback = A.Fake <Action <bool> >();

            A.CallTo(() => connectCallback(false)).Invokes(() => {
                webSocket.OnOpen += Raise.WithEmpty();
            });

            webSocketJetConnection.Connect(connectCallback, 1234.56);

            AssertTimerCallsOnConnect(timer, 1234.56);
            A.CallTo(() => connectCallback(true)).MustNotHaveHappened();
            A.CallTo(() => connectCallback(false)).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 28
0
        public void LoadingNewConfigFileUpdatesConfigViewModel()
        {
            var configService = A.Fake <IConfigService>();
            var config        = new Config();

            A.CallTo(() => configService.Config).Returns(config);

            var viewModel = new ConfigViewModel(configService);

            Assert.Empty(viewModel.OutputChannels);
            Assert.Empty(viewModel.InputChannels);

            config.Channels = new System.Collections.ObjectModel.ObservableCollection <Channel>
            {
                new InputChannel()
            };

            configService.ConfigFileLoaded += Raise.WithEmpty();

            Assert.Single(viewModel.InputChannels);
        }
Esempio n. 29
0
        public void The_change_time_is_the_time_when_the_new_desk_state_ends()
        {
            var now = new DateTime(2014, 5, 11);

            TestableDateTime.DateTime = A.Fake <IDateTime>();
            A.CallTo(() => TestableDateTime.DateTime.Now).Returns(now);

            var timer  = A.Fake <ITimer>();
            var target = new StandUpModel(timer, SittingTime, StandingTime);

            Assert.That(target.ChangeTime, Is.EqualTo(now.Add(SittingTime)));

            timer.Tick += Raise.WithEmpty().Now;
            target.NewDeskStateStarted();

            Assert.That(target.ChangeTime, Is.EqualTo(now.Add(StandingTime)));

            timer.Tick += Raise.WithEmpty().Now;
            target.NewDeskStateStarted();

            Assert.That(target.ChangeTime, Is.EqualTo(now.Add(SittingTime)));
        }
        public void ShouldLoadFirstGridFromTheListOnStart()
        {
            //given
            var activeWindow     = A.Fake <WindowRepresentation>();
            var windowDimensions = new Dimensions(new Point(0, 0), new Size(100, 100));

            A.CallTo(() => activeWindow.Dimensions).Returns(windowDimensions);

            var windowManager = A.Fake <WindowManager>();

            A.CallTo(() => windowManager.GetActiveWindow()).Returns(activeWindow);

            var dummyHotkeyConfiguration = A.Fake <GridHotkeyConfiguration>();

            A.CallTo(() => dummyHotkeyConfiguration.Left).Returns(A.Fake <GlobalHotkey>());
            A.CallTo(() => dummyHotkeyConfiguration.Right).Returns(A.Fake <GlobalHotkey>());
            A.CallTo(() => dummyHotkeyConfiguration.Up).Returns(A.Fake <GlobalHotkey>());
            A.CallTo(() => dummyHotkeyConfiguration.Down).Returns(A.Fake <GlobalHotkey>());

            var gridElementDimensions = new Dimensions(new Point(0, 0), new Size(1, 1));

            var windowsOnGridController = new WindowsOnGridController(dummyHotkeyConfiguration);
            var gridConfigs             = new[]
            {
                new GridConfig
                {
                    Name = "asdf", GridElements = new [] { gridElementDimensions }
                }
            };
            var gridFactory = new GridFactory(windowManager);

            new GridSwitcher(gridConfigs, gridFactory, windowsOnGridController);

            //when
            dummyHotkeyConfiguration.Left.HotkeyPressed += Raise.WithEmpty();

            //then
            A.CallTo(() => activeWindow.SetDimensions(A <Dimensions> .That.Matches(newDimensions => newDimensions.Equals(gridElementDimensions)))).MustHaveHappened();
        }