示例#1
0
        public void UploadenBestandTestAddContentVolledigeCursusTitelCheck()
        {
            //Arrange
            using (var ms = new MemoryStream())
            {
                using (var writer = new StreamWriter(ms))
                {
                    var fileMock = new Mock <IFormFile>();
                    writer.WriteLine("Titel: C# Programmeren");
                    writer.WriteLine("Cursuscode: CNETIN");
                    writer.WriteLine("Duur: 5 dagen");
                    writer.WriteLine("Startdatum: 11/10/2014 ");
                    writer.WriteLine("");

                    writer.Flush();
                    ms.Position = 0;
                    fileMock.Setup(m => m.OpenReadStream()).Returns(ms);
                    fileMock.Setup(m => m.Length).Returns(5);


                    MockAgent mockAgent = new MockAgent();
                    var       target    = new CursusController(mockAgent);

                    //Act
                    var result = target.Create(fileMock.Object);

                    //Assert
                    Assert.AreEqual(1, mockAgent.NumberOfTimesAddCalled);
                    Assert.AreEqual("C# Programmeren", mockAgent.LijstCursusAddToevoeging[0].Cursus.Titel);
                }
            }
        }
示例#2
0
        public void UploadenBestandFaalendBestandCursusStartdatum()
        {
            //Arrange
            using (var ms = new MemoryStream())
            {
                using (var writer = new StreamWriter(ms))
                {
                    var fileMock = new Mock <IFormFile>();
                    writer.WriteLine("Titel: C# Programmeren");
                    writer.WriteLine("Cursuscode: CNETIN");
                    writer.WriteLine("Duur: 5 dagen");
                    writer.WriteLine("11/10/2014 ");
                    writer.WriteLine("");

                    writer.Flush();
                    ms.Position = 0;
                    fileMock.Setup(m => m.OpenReadStream()).Returns(ms);
                    fileMock.Setup(m => m.Length).Returns(5);


                    MockAgent mockAgent = new MockAgent();
                    var       target    = new CursusController(mockAgent);

                    //Act
                    var result = target.Create(fileMock.Object);
                    // Assert
                    CursusCreateMessageViewModel viewModel = (CursusCreateMessageViewModel)(result as ViewResult).Model;
                    Assert.IsNotNull(viewModel);
                    Assert.AreEqual(4, viewModel.ErrorAtLine);
                }
            }
        }
示例#3
0
        public void UploadenBestandTestVerwijzingMessagePage()
        {
            // Arrange
            var fileMock = new Mock <IFormFile>();
            var lines    = File.ReadLines(@"TestFile\goedvoorbeeld.txt").ToList();

            using (var memoryStream = new MemoryStream())
            {
                using (var streamWriter = new StreamWriter(memoryStream))
                {
                    for (var i = 0; i < lines.Count; i++)
                    {
                        streamWriter.WriteLine(lines[i]);
                    }
                    streamWriter.Flush();
                    memoryStream.Position = 0;

                    fileMock.Setup(m => m.OpenReadStream()).Returns(memoryStream);
                    fileMock.Setup(m => m.Length).Returns(5);

                    MockAgent mockAgent = new MockAgent();
                    var       target    = new CursusController(mockAgent);

                    //Act
                    var result = target.Create(fileMock.Object);
                    // Assert
                    Assert.IsInstanceOfType(result, typeof(IActionResult));
                    Assert.AreEqual("CursusCreateMessage", (result as ViewResult).ViewName);
                }
            }
        }
示例#4
0
        public void UploadenBestandTestVerwijzingMessagePageModelContentInsertCount4()
        {
            // Arrange
            var fileMock = new Mock <IFormFile>();
            var lines    = File.ReadLines(@"TestFile\goedvoorbeeld.txt").ToList();

            using (var memoryStream = new MemoryStream())
            {
                using (var streamWriter = new StreamWriter(memoryStream))
                {
                    for (var i = 0; i < lines.Count; i++)
                    {
                        streamWriter.WriteLine(lines[i]);
                    }
                    streamWriter.Flush();
                    memoryStream.Position = 0;

                    fileMock.Setup(m => m.OpenReadStream()).Returns(memoryStream);
                    fileMock.Setup(m => m.Length).Returns(5);

                    MockAgent mockAgent = new MockAgent();
                    var       target    = new CursusController(mockAgent);

                    //Act
                    var result = target.Create(fileMock.Object);
                    // Assert
                    CursusCreateMessageViewModel viewModel = (CursusCreateMessageViewModel)(result as ViewResult).Model;
                    Assert.IsNotNull(viewModel);
                    Assert.AreEqual(4, viewModel.SuccesInsertCount);
                }
            }
        }
示例#5
0
        public void TestenFileUploadOntvangenBijController()
        {
            //Arrange
            using (var ms = new MemoryStream())
            {
                using (var writer = new StreamWriter(ms))
                {
                    var fileMock = new Mock <IFormFile>();
                    writer.WriteLine("Titel: C# Programmeren");
                    writer.WriteLine("Cursuscode: CNETIN");
                    writer.WriteLine("Duur: 5 dagen");
                    writer.WriteLine("Startdatum: 11/10/2014 ");
                    writer.WriteLine("");

                    writer.Flush();
                    ms.Position = 0;
                    fileMock.Setup(m => m.OpenReadStream()).Returns(ms);
                    fileMock.Setup(m => m.Length).Returns(5);


                    MockAgent mockAgent = new MockAgent();
                    var       target    = new CursusController(mockAgent);

                    //Act
                    var result = target.Create(fileMock.Object);
                    //Assert
                    Assert.IsInstanceOfType(result, typeof(IActionResult));
                }
            }
        }