public void SwagOMeterViewModelShouldAwardSwagAndCanSwagSetToFalseWhenSwagAndAttendeesAreAllUsedUpAfterAward()
        {
            // Arrange
            var mockAttendee = new Mock<IAttendee>();
            mockAttendee.SetupGet(a => a.Name).Returns("Bob");

            var mockSwag = new Mock<ISwag>();
            mockSwag.SetupGet(s => s.Company).Returns("Company");
            mockSwag.SetupGet(s => s.Thing).Returns("Thing");

            var stubAttendeeSource = new Mock<IAttendeeSource>();

            var stubSwagSource = new Mock<ISwagSource>();

            var stubWinnersSource = new Mock<IWinnersSource>();

            var stubSwagOMeterEngine = new Mock<ISwagOMeterAwardEngine>();
            stubSwagOMeterEngine.Setup(e => e.CheckCanSwag()).Returns(true);
            stubSwagOMeterEngine.SetupSequence(e => e.CanSwag).Returns(true).Returns(false);
            stubSwagOMeterEngine.SetupGet(e => e.AwardedSwag).Returns(mockSwag.Object);
            stubSwagOMeterEngine.SetupGet(e => e.WinningAttendee).Returns(mockAttendee.Object);

            // Act
            var viewModel = new SwagOMeterViewModel(stubAttendeeSource.Object, stubSwagSource.Object, stubWinnersSource.Object, stubSwagOMeterEngine.Object);
            viewModel.ViewReady();
            viewModel.AwardSwagCommand.Execute(null);

            // Assert
            StringAssert.Matches(viewModel.WinningAttendee, new Regex("Bob"));
            StringAssert.Matches(viewModel.WonSwag, new Regex("Company Thing"));
            Assert.IsFalse(viewModel.CanSwag);
        }
        public SwagOMeterView()
        {
            var errorMessage = new DisplayErrorMessages();

            var attendeeSource = new AttendeeSource(errorMessage);
            var swagSource = new SwagSource(errorMessage);

            _viewModel = new SwagOMeterViewModel(attendeeSource, swagSource, new WinnersSource(), new SwagOMeterAwardEngine(attendeeSource, swagSource));

            _viewModel.Close += (s, e) => Close();
            _viewModel.PlayMusic += (s, e) => mediaElement.Play();
            _viewModel.StopMusic += (s, e) => mediaElement.Pause();

            DataContext = _viewModel;

            InitializeComponent();
        }
Example #3
0
        public SwagOMeterView()
        {
            var fileDetailProvider = FileDetailProvider.Create(Settings.Default.FileLocation, (string)Resources["SwagWinnersFile"]);

            var errorMessage = new DisplayErrorMessages();

            var attendeeSource = new AttendeeSource(errorMessage);
            var swagSource = new SwagSource(errorMessage);

            var viewModel = new SwagOMeterViewModel(attendeeSource, swagSource, new WinnersSource(fileDetailProvider), new SwagOMeterAwardEngine(Settings.Default.FileLocation, attendeeSource, swagSource, Constants.AttendeesFilename, Constants.SwagFilename), Settings.Default.SaveWinnersOnExit);

            viewModel.Close += (s, e) => Close();
            viewModel.PlayMusic += (s, e) => mediaElement.Play();
            viewModel.StopMusic += (s, e) => mediaElement.Pause();

            DataContext = viewModel;

            InitializeComponent();
        }
        public void SwagOMeterViewModelShouldSaveAnyWinnerWhenWinnersHaveBeenAssigned()
        {
            // Arrange
            var mockAttendee = new Mock<IAttendee>();
            mockAttendee.SetupGet(a => a.Name).Returns("Bob");

            var mockSwagObject = new Mock<ISwag>();
            mockSwagObject.SetupGet(a => a.Thing).Returns("Pants");

            var stubAttendees = new List<IAttendee> { mockAttendee.Object };
            var stubSwag = new List<ISwag> { mockSwagObject.Object };

            var stubAttendeeSource = new Mock<IAttendeeSource>();
            stubAttendeeSource.Setup(sa => sa.Load(It.IsAny<string>())).Returns(stubAttendees);

            var stubSwagSource = new Mock<ISwagSource>();
            stubSwagSource.Setup(ss => ss.Load(It.IsAny<string>())).Returns(stubSwag);

            var stubWinnersSource = new Mock<IWinnersSource>();
            stubWinnersSource.Setup(ws => ws.Save(It.IsAny<IList<IWinner>>())).Verifiable();

            var mockSwagOMeterEngine = new Mock<ISwagOMeterAwardEngine>();
            mockSwagOMeterEngine.SetupSequence(e => e.CheckCanSwag()).Returns(true);
            mockSwagOMeterEngine.SetupGet(e => e.CanSwag).Returns(true);

            // Act
            var viewModel = new SwagOMeterViewModel(stubAttendeeSource.Object, stubSwagSource.Object, stubWinnersSource.Object, mockSwagOMeterEngine.Object);
            viewModel.ViewReady();
            viewModel.AwardSwagCommand.Execute(null);
            viewModel.CloseCommand.Execute(null);

            // Assert
            mockSwagOMeterEngine.Verify(e => e.SaveWinners(It.Is<IWinnersSource>(ws => ws == stubWinnersSource.Object)), Times.Once());
        }
        public void SwagOMeterViewModelShouldNotBeAbleToSwagWhenAnAttendeeDoesntWantTheSwagButNoOtherAttendeeOrSwagIsLeft()
        {
            // Arrange
            var stubAttendee = new Mock<IAttendee>();
            var stubSwag = new Mock<ISwag>();

            var stubAttendeeSource = new Mock<IAttendeeSource>();

            var stubSwagSource = new Mock<ISwagSource>();

            var stubWinnersSource = new Mock<IWinnersSource>();

            var stubSwagOMeterEngine = new Mock<ISwagOMeterAwardEngine>();
            stubSwagOMeterEngine.SetupSequence(e => e.CheckCanSwag()).Returns(true).Returns(false);
            stubSwagOMeterEngine.SetupGet(e => e.AwardedSwag).Returns(stubSwag.Object);
            stubSwagOMeterEngine.SetupGet(e => e.WinningAttendee).Returns(stubAttendee.Object);
            stubSwagOMeterEngine.SetupSequence(e => e.CanSwag).Returns(true).Returns(false);

            // Act
            var viewModel = new SwagOMeterViewModel(stubAttendeeSource.Object, stubSwagSource.Object, stubWinnersSource.Object, stubSwagOMeterEngine.Object);
            viewModel.ViewReady();
            viewModel.AwardSwagCommand.Execute(null);
            viewModel.AlreadyGotSwagCommand.Execute(null);

            // Assert
            Assert.IsNull(viewModel.WinningAttendee);
            Assert.IsNull(viewModel.WonSwag);
            Assert.IsFalse(viewModel.CanSwag);
        }
        public void SwagOMeterViewModelShouldLoadAttendeesWhenRequestedButShouldNotBeSwagableWhenNoSwagIsPresent()
        {
            // Arrange
            var stubAttendeeSource = new Mock<IAttendeeSource>();

            var stubSwagSource = new Mock<ISwagSource>();

            var stubWinnersSource = new Mock<IWinnersSource>();

            var stubSwagOMeterEngine = new Mock<ISwagOMeterAwardEngine>();

            // Act
            var viewModel = new SwagOMeterViewModel(stubAttendeeSource.Object, stubSwagSource.Object, stubWinnersSource.Object, stubSwagOMeterEngine.Object);
            viewModel.ViewReady();

            // Assert
            Assert.IsFalse(viewModel.CanSwag);
            Assert.IsNull(viewModel.WinningAttendee);
            Assert.IsNull(viewModel.WonSwag);
        }
        public void SwagOMeterViewModelShouldLoadAttendeesWhenRequestedButHaveNoWinnerOrSwagAssigned()
        {
            // Arrange
            var stubAttendeeSource = new Mock<IAttendeeSource>();

            var stubSwagSource = new Mock<ISwagSource>();

            var stubWinnersSource = new Mock<IWinnersSource>();

            var stubSwagOMeterEngine = new Mock<ISwagOMeterAwardEngine>();
            stubSwagOMeterEngine.Setup(e => e.CheckCanSwag()).Returns(true);

            // Act
            var viewModel = new SwagOMeterViewModel(stubAttendeeSource.Object, stubSwagSource.Object, stubWinnersSource.Object, stubSwagOMeterEngine.Object);
            viewModel.ViewReady();

            // Assert
            Assert.IsTrue(viewModel.CanSwag);
            Assert.IsNull(viewModel.WinningAttendee);
            Assert.IsNull(viewModel.WonSwag);
        }
        public void SwagOMeterViewModelShouldHaveCanSwagSetToTrueWhenAWinnerIsNotPresentAndTheSwagIsReAssigned()
        {
            // Arrange
            var mockAttendee = new Mock<IAttendee>();
            var mockSwag = new Mock<ISwag>();

            var stubAttendeeSource = new Mock<IAttendeeSource>();

            var stubSwagSource = new Mock<ISwagSource>();

            var stubWinnersSource = new Mock<IWinnersSource>();

            var stubSwagOMeterEngine = new Mock<ISwagOMeterAwardEngine>();
            stubSwagOMeterEngine.Setup(e => e.CheckCanSwag()).Returns(true);
            stubSwagOMeterEngine.SetupSequence(e => e.CanSwag).Returns(true);
            stubSwagOMeterEngine.SetupGet(e => e.AwardedSwag).Returns(mockSwag.Object);
            stubSwagOMeterEngine.SetupGet(e => e.WinningAttendee).Returns(mockAttendee.Object);

            // Act
            var viewModel = new SwagOMeterViewModel(stubAttendeeSource.Object, stubSwagSource.Object, stubWinnersSource.Object, stubSwagOMeterEngine.Object);
            viewModel.ViewReady();
            viewModel.AwardSwagCommand.Execute(null);
            viewModel.AttendeeNotPresentCommand.Execute(null);

            // Assert
            Assert.IsNull(viewModel.WinningAttendee);
            Assert.IsNull(viewModel.WonSwag);
            Assert.IsTrue(viewModel.CanSwag);
        }