Ejemplo n.º 1
0
        public void EditThingViewModelShouldNotSaveAvailableSwagToTheSwagSourceWhenChangesHaveNotBeenMade()
        {
            // Arrange
            var stubSwag1 = new Mock <ISwag>();
            var stubSwag2 = new Mock <ISwag>();
            var stubSwag3 = new Mock <ISwag>();

            var stubSwag = new List <ISwag> {
                stubSwag1.Object, stubSwag2.Object, stubSwag3.Object
            };

            var stubSwagSource = new Mock <ISwagSource>();

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

            const string stubPath = "A Path";

            var stubDiaglogFactory = new Mock <IDialogFactory <ISwag> >();

            var stubView = new Mock <ICanClose>();

            // Act
            var viewModel = new EditThingsViewModel <ISwag, ISwagSource>(stubSwagSource.Object, stubPath, stubDiaglogFactory.Object);

            viewModel.RegisterView(stubView.Object);
            viewModel.ViewReady();
            viewModel.SaveCommand.Execute(null);

            // Assert
            Assert.AreEqual(3, viewModel.Things.Count());
            stubSwagSource.Verify(ss => ss.Save(It.IsAny <IList <ISwag> >(), It.Is <string>(s => s.StartsWith(stubPath))), Times.Never());
        }
Ejemplo n.º 2
0
        public void EditThingViewModelSaveAvailableSwagToTheSwagSourceWhenChangesHaveBeenMade()
        {
            // Arrange
            var stubSwag1 = new Mock<ISwag>();
            var stubSwag2 = new Mock<ISwag>();
            var stubSwag3 = new Mock<ISwag>();

            var stubNewSwag = new Mock<ISwag>();

            var stubSwag = new List<ISwag> { stubSwag1.Object, stubSwag2.Object, stubSwag3.Object };

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

            const string stubPath = "A Path";

            var stubCreateSwag = new Mock<ICreateNewThings<ISwag>>();
            stubCreateSwag.Setup(cs => cs.ShowDialog());
            stubCreateSwag.SetupGet(cs => cs.NewThing).Returns(stubNewSwag.Object);

            var stubDiaglogFactory = new Mock<IDialogFactory<ISwag>>();
            stubDiaglogFactory.Setup(f => f.CreateDialog()).Returns(stubCreateSwag.Object);

            var stubView = new Mock<ICanClose>();

            // Act
            var viewModel = new EditThingsViewModel<ISwag, ISwagSource>(stubSwagSource.Object, stubPath, stubDiaglogFactory.Object);
            viewModel.RegisterView(stubView.Object);
            viewModel.ViewReady();
            viewModel.CreateCommand.Execute(null);
            viewModel.SaveCommand.Execute(null);

            // Assert
            stubSwagSource.Verify(ss => ss.Save(It.IsAny<IList<ISwag>>(), It.Is<string>(s => s.StartsWith(stubPath))), Times.Once());
        }
Ejemplo n.º 3
0
        public void EditThingViewModelShoulAddNewSwagToTheSwagSourceWhenChangesHaveBeenMade()
        {
            // Arrange
            var stubSwag1 = new Mock <ISwag>();
            var stubSwag2 = new Mock <ISwag>();
            var stubSwag3 = new Mock <ISwag>();

            var stubNewSwag = new Mock <ISwag>();

            var stubSwag = new List <ISwag> {
                stubSwag1.Object, stubSwag2.Object, stubSwag3.Object
            };

            var stubSwagSource = new Mock <ISwagSource>();

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

            const string stubPath = "A Path";

            var stubCreateSwag = new Mock <ICreateNewThings <ISwag> >();

            stubCreateSwag.Setup(cs => cs.ShowDialog());
            stubCreateSwag.SetupGet(cs => cs.NewThing).Returns(stubNewSwag.Object);

            var stubDiaglogFactory = new Mock <IDialogFactory <ISwag> >();

            stubDiaglogFactory.Setup(f => f.CreateDialog()).Returns(stubCreateSwag.Object);

            var stubView = new Mock <ICanClose>();

            // Act
            var viewModel = new EditThingsViewModel <ISwag, ISwagSource>(stubSwagSource.Object, stubPath, stubDiaglogFactory.Object);

            viewModel.RegisterView(stubView.Object);
            viewModel.ViewReady();
            viewModel.CreateCommand.Execute(null);
            viewModel.SaveCommand.Execute(null);

            // Assert
            Assert.AreEqual(4, viewModel.Things.Count());
            Assert.IsTrue(viewModel.Things.Contains(stubNewSwag.Object));
        }
Ejemplo n.º 4
0
        public void EditThingViewModelSaveAvailableSwagToTheSwagSourceWhenChangesHaveBeenMade()
        {
            // Arrange
            var stubSwag1 = new Mock <ISwag>();
            var stubSwag2 = new Mock <ISwag>();
            var stubSwag3 = new Mock <ISwag>();

            var stubNewSwag = new Mock <ISwag>();

            var stubSwag = new List <ISwag> {
                stubSwag1.Object, stubSwag2.Object, stubSwag3.Object
            };

            var stubSwagSource = new Mock <ISwagSource>();

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

            const string stubPath = "A Path";

            var stubCreateSwag = new Mock <ICreateNewThings <ISwag> >();

            stubCreateSwag.Setup(cs => cs.ShowDialog());
            stubCreateSwag.SetupGet(cs => cs.NewThing).Returns(stubNewSwag.Object);

            var stubDiaglogFactory = new Mock <IDialogFactory <ISwag> >();

            stubDiaglogFactory.Setup(f => f.CreateDialog()).Returns(stubCreateSwag.Object);

            var stubView = new Mock <ICanClose>();

            // Act
            var viewModel = new EditThingsViewModel <ISwag, ISwagSource>(stubSwagSource.Object, stubPath, stubDiaglogFactory.Object);

            viewModel.RegisterView(stubView.Object);
            viewModel.ViewReady();
            viewModel.CreateCommand.Execute(null);
            viewModel.SaveCommand.Execute(null);

            // Assert
            stubSwagSource.Verify(ss => ss.Save(It.IsAny <IList <ISwag> >(), It.Is <string>(s => s.StartsWith(stubPath))), Times.Once());
        }
Ejemplo n.º 5
0
        public void EditThingViewModelShoulAddNewSwagToTheSwagSourceWhenChangesHaveBeenMade()
        {
            // Arrange
            var stubSwag1 = new Mock<ISwag>();
            var stubSwag2 = new Mock<ISwag>();
            var stubSwag3 = new Mock<ISwag>();

            var stubNewSwag = new Mock<ISwag>();

            var stubSwag = new List<ISwag> { stubSwag1.Object, stubSwag2.Object, stubSwag3.Object };

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

            const string stubPath = "A Path";

            var stubCreateSwag = new Mock<ICreateNewThings<ISwag>>();
            stubCreateSwag.Setup(cs => cs.ShowDialog());
            stubCreateSwag.SetupGet(cs => cs.NewThing).Returns(stubNewSwag.Object);

            var stubDiaglogFactory = new Mock<IDialogFactory<ISwag>>();
            stubDiaglogFactory.Setup(f => f.CreateDialog()).Returns(stubCreateSwag.Object);

            var stubView = new Mock<ICanClose>();

            // Act
            var viewModel = new EditThingsViewModel<ISwag, ISwagSource>(stubSwagSource.Object, stubPath, stubDiaglogFactory.Object);
            viewModel.RegisterView(stubView.Object);
            viewModel.ViewReady();
            viewModel.CreateCommand.Execute(null);
            viewModel.SaveCommand.Execute(null);

            // Assert
            Assert.AreEqual(4, viewModel.Things.Count());
            Assert.IsTrue(viewModel.Things.Contains(stubNewSwag.Object));
        }
Ejemplo n.º 6
0
        public void EditThingViewModelShouldNotSaveAvailableSwagToTheSwagSourceWhenChangesHaveNotBeenMade()
        {
            // Arrange
            var stubSwag1 = new Mock<ISwag>();
            var stubSwag2 = new Mock<ISwag>();
            var stubSwag3 = new Mock<ISwag>();

            var stubSwag = new List<ISwag> { stubSwag1.Object, stubSwag2.Object, stubSwag3.Object };

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

            const string stubPath = "A Path";

            var stubDiaglogFactory = new Mock<IDialogFactory<ISwag>>();

            var stubView = new Mock<ICanClose>();

            // Act
            var viewModel = new EditThingsViewModel<ISwag, ISwagSource>(stubSwagSource.Object, stubPath, stubDiaglogFactory.Object);
            viewModel.RegisterView(stubView.Object);
            viewModel.ViewReady();
            viewModel.SaveCommand.Execute(null);

            // Assert
            Assert.AreEqual(3, viewModel.Things.Count());
            stubSwagSource.Verify(ss => ss.Save(It.IsAny<IList<ISwag>>(), It.Is<string>(s => s.StartsWith(stubPath))), Times.Never());
        }