Beispiel #1
0
        public async Task CreateWithValidReturnsCreatedResult()
        {
            // ARRANGE
            var cInstantie = new CursusInstantie {
                Id = 1, Cursus = new Cursus {
                }, CursusId = 1, StartDatum = DateTime.Now
            };
            var cursist = new Cursist {
                Id = 1, Naam = "Test1", Achternaam = "Test1", Cursussen = new List <CursusInstantie>()
                {
                    cInstantie
                }
            };

            _cursistService.Setup(x => x.CreateAsync(It.IsAny <Cursist>()))
            .Returns(Task.FromResult(cursist));
            _cursistInstantieService.Setup(x => x.GetAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(cInstantie));
            _cursistInstantieService.Setup(x => x.AddCursist(It.IsAny <int>(), It.IsAny <Cursist>()))
            .Returns(Task.FromResult(cInstantie));

            var inputDto = new CursistToCreateDto {
                CursusInstantieId = 1, Achternaam = "Test1", Naam = "Test1"
            };
            // Act
            var result = await _cursistenController.CreateAsync(inputDto);

            var objectResult = result as CreatedNegotiatedContentResult <CursistToDetailsDto>;

            // Assert
            Assert.IsNotNull(objectResult);
        }
Beispiel #2
0
 private CursusInstantieBuilder()
 {
     _cursusInstantie = new CursusInstantie
     {
         Id = _random.Next()
     };
 }
Beispiel #3
0
        public void InsertCursusFaalendDuplicate()
        {
            using (var repo = new CursusRepositoryMock())
            {
                //Arrange

                var target = new CursusController(repo);
                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "C# testing"
                };

                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 10),
                    Cursus     = cursus
                };
                target.Post(cursusInstantie);


                //Act
                var result = target.Post(cursusInstantie);

                //Assert
                Assert.AreEqual(2, repo.TimesInsertCalled);
                Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
            }
        }
Beispiel #4
0
        public void VoegMeerdereCursusInstantiesVindSlechts1ContentCheckNonSame()
        {
            using (var repo = new CursusRepository(new DatabaseContext(_options)))
            {
                //Arrange
                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "C# testing"
                };
                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 15),
                    Cursus     = cursus
                };
                repo.Insert(cursusInstantie);

                var cursusInstantie2 = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 3, 10),
                    Cursus     = cursus
                };
                repo.Insert(cursusInstantie2);

                DateTime targetDateStart = new DateTime(2016, 10, 10);
                DateTime targetDateEind  = new DateTime(2016, 10, 17);


                //Act
                var result = repo.FindBy(c => c.Startdatum >= targetDateStart && c.Startdatum < targetDateEind);
                //Assert
                Assert.AreEqual(targetDateStart.AddDays(5), result.First().Startdatum);
            }
        }
Beispiel #5
0
        public void CursusPutTest()
        {
            using (var repo = new CursusRepositoryMock())
            {
                Assert.AreEqual(0, repo.TimesUpdateCalled);

                var target = new CursusController(repo);

                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "C# testing"
                };
                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 10),
                    Cursus     = cursus
                };
                target.Put(cursusInstantie);

                Assert.AreEqual(1, repo.TimesUpdateCalled);
                Assert.AreEqual(cursusInstantie, repo.UpdateLastCallContent);
            }
        }
Beispiel #6
0
        public void InsertCursusFaalendDuplicateErrorMessage()
        {
            using (var repo = new CursusRepositoryMock())
            {
                var target = new CursusController(repo);
                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "C# testing"
                };

                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 10),
                    Cursus     = cursus
                };
                target.Post(cursusInstantie);


                //Act
                var result = target.Post(cursusInstantie);

                //Assert
                Assert.AreEqual(2, repo.TimesInsertCalled);
                Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
                var testResult = (result as BadRequestObjectResult).Value;
                Assert.AreEqual("This key already exist", (testResult as Foutmelding).ErrorMessage);
            }
        }
Beispiel #7
0
        public async Task <CursusInstantieUploadResultSet> CreateRangeAsync(List <CursusInstantie> cursusInstanties)
        {
            var duplicates = new List <CursusInstantie>();
            var toReturn   = new List <CursusInstantie>();

            foreach (var ci in cursusInstanties)
            {
                var isDupAsWhole = await _context.CursusInstanties.AnyAsync(x => x.StartDatum == ci.StartDatum && x.Cursus.Code == ci.Cursus.Code);

                if (isDupAsWhole)
                {
                    duplicates.Add(ci);
                }
                else
                {
                    var isDup = await _context.Cursussen.AnyAsync(x => x.Code == ci.Cursus.Code && ci.Cursus.Duur == x.Duur);

                    if (isDup || toReturn.Any(c => c.Cursus.Code == ci.Cursus.Code && c.Cursus.Duur == ci.Cursus.Duur))
                    {
                        var existingCursus = await _context.Cursussen
                                             .Include(x => x.CursusInstanties)
                                             .FirstOrDefaultAsync(x => x.Code == ci.Cursus.Code);

                        // If not in Database then it is in the list
                        if (existingCursus == null)
                        {
                            existingCursus = toReturn.FirstOrDefault(c => c.Cursus.Code == ci.Cursus.Code && c.Cursus.Duur == ci.Cursus.Duur).Cursus;
                        }

                        var instantie = new CursusInstantie
                        {
                            Cursus     = existingCursus,
                            CursusId   = existingCursus.Id,
                            StartDatum = ci.StartDatum,
                        };

                        existingCursus.CursusInstanties.Add(instantie);
                        toReturn.Add(instantie);
                    }
                    else
                    {
                        var dubCursus = toReturn.FirstOrDefault(x => x.Cursus.Code == ci.Cursus.Code && x.Cursus.Duur == ci.Cursus.Duur) != null
                                ? toReturn.FirstOrDefault(x => x.Cursus.Code == ci.Cursus.Code && x.Cursus.Duur == ci.Cursus.Duur).Cursus
                                : ci.Cursus;

                        ci.Cursus = dubCursus;
                        _context.CursusInstanties.Add(ci);
                        toReturn.Add(ci);
                    }
                }
            }

            await _context.SaveChangesAsync();

            return(new CursusInstantieUploadResultSet
            {
                Uploaded = toReturn,
                Duplicate = duplicates
            });
        }
        private List <CursusInstantie> TestData()
        {
            var date1   = new DateTime(2020, 2, 2);
            var date2   = new DateTime(2020, 4, 4);
            var date3   = new DateTime(2020, 3, 5);
            var cursus1 = new Cursus()
            {
                Id = 1, Titel = "unittest", Duur = 5
            };
            var cursus2 = new Cursus()
            {
                Id = 2, Titel = "mvc", Duur = 5
            };
            var testObject1 = new CursusInstantie()
            {
                Id = 1, StartDatum = date1, Cursus = cursus1
            };
            var testObject2 = new CursusInstantie()
            {
                Id = 2, StartDatum = date2, Cursus = cursus2
            };
            var testObject3 = new CursusInstantie()
            {
                Id = 3, StartDatum = date3, Cursus = cursus2
            };
            var testList = new List <CursusInstantie>()
            {
                testObject1, testObject2, testObject3
            };

            return(testList);
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='value'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <object> PostAsync(this ICASService operations, CursusInstantie value = default(CursusInstantie), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.PostWithHttpMessagesAsync(value, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Beispiel #10
0
        public void TestFind()
        {
            using (var repo = new CursusRepository(new DatabaseContext(_options)))
            {
                //Arrange
                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "Name"
                };
                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 10),
                    Cursus     = cursus
                };
                //Act
                repo.Insert(cursusInstantie);
                var res = repo.Find(1);
            }

            using (var repo = new CursusRepository(new DatabaseContext(_options)))
            {
                //Assert
                var result = repo.Find(1);
                Assert.AreEqual("test", result.Cursus.Cursuscode);
                Assert.AreEqual(5, result.Cursus.Duur);

                Assert.AreEqual("Name", result.Cursus.Titel);
            }
        }
Beispiel #11
0
        public void TestAdd()
        {
            using (var repo = new CursusRepository(new DatabaseContext(_options)))
            {
                //Arrange
                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "Name"
                };
                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 10),
                    Cursus     = cursus
                };
                //Act
                repo.Insert(cursusInstantie);
            }


            using (var repo = new CursusRepository(new DatabaseContext(_options)))
            {
                Assert.AreEqual(1, repo.Count());
            }
        }
Beispiel #12
0
        public void CursistInsertDeleteThenGetAllCount0()
        {
            using (var repo = new CursistRepository(new DatabaseContext(_options)))
            {
                //Arrange
                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "C# testing"
                };
                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 15),
                    Cursus     = cursus
                };

                Cursist cursist = new Cursist()
                {
                    Voornaam          = "Kees",
                    Achternaam        = "Koning",
                    CursusInstantieID = 1
                };
                //Act
                repo.Insert(cursist);
                repo.Delete(1);
                var result = repo.FindAll();
                //Assert
                Assert.IsInstanceOfType(result, typeof(IEnumerable <Cursist>));
                Assert.AreEqual(0, result.Count());
            }
        }
Beispiel #13
0
        public void GetCursusInstantieByWeek_ShouldReturnCursusInstanties()
        {
            int cursusWeek = 28; // Week number matches CursusInstantie StartDatum.
            int cursusYear = 2020;

            Cursus cursus = new Cursus {
                Id = 1, Duur = 5, Titel = "Java Persistence API", Code = "JPA"
            };

            CursusInstantie cursusInstantie = new CursusInstantie()
            {
                StartDatum = new DateTime(06 / 07 / 2020),
                CursusId   = cursus.Id,
                Cursus     = cursus
            };

            IEnumerable <CursusInstantie> cursusInstantieList = new List <CursusInstantie> {
                cursusInstantie
            };

            Task <IEnumerable <CursusInstantie> > getByWeekAndYearMethodResponse = Task.FromResult(cursusInstantieList);

            _cursusInstantierepository.Setup(cir => cir.GetByWeekAndYear(cursusWeek, cursusYear))
            .Returns(getByWeekAndYearMethodResponse);

            Task <IEnumerable <CursusInstantieViewModel> > actualResponse = _cursusInstantieController.GetCursusInstantieByWeek(cursusWeek, cursusYear);

            Assert.IsNotNull(actualResponse);
            Assert.IsInstanceOfType(actualResponse, typeof(Task <IEnumerable <CursusInstantieViewModel> >));
            Assert.IsTrue(actualResponse.Result.Count() == 1);
        }
Beispiel #14
0
        public Task <HttpOperationResponse <object> > PostWithHttpMessagesAsync(CursusInstantie value = null, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            NumberOfTimesAddCalled++;
            LijstCursusAddToevoeging.Add(value);
            var _result = new HttpOperationResponse <object>();

            _result.Response = new HttpResponseMessage(HttpStatusCode.OK);
            return(Task.FromResult(_result));
        }
Beispiel #15
0
 public override void Insert(CursusInstantie item)
 {
     InsertLastCallContent = item;
     TimesInsertCalled++;
     if (InsertLastCallContent?.GetHashCode() == item.GetHashCode())
     {
         throw new DbUpdateException("Duplicate cursus", new InvalidOperationException());
     }
 }
Beispiel #16
0
        public void DoesCursusInstantieExistReturnsFalseIfCursusInstanceDoesNotExist()
        {
            IEnumerable <CursusInstantie> cursusInstantieMock = null;

            _cursusRepositoryMock.Setup(x => x.GetCursusInstanties()).Returns(cursusInstantieMock);

            CursusInstantie cursusInstantie = CursusInstantieBuilder.New().Build();

            var result = _sut.DoesNotCursusInstantieExist(cursusInstantie);

            Assert.IsFalse(result);
        }
Beispiel #17
0
        public void DoesCursusInstantieExistReturnsTrueIfCursusInstanceAlreadyExist()
        {
            CursusInstantie cursusInstantieMock = CursusInstantieBuilder.New().Build();

            _cursusRepositoryMock.Setup(x => x.GetCursusInstantieById(It.IsAny <int>())).Returns(cursusInstantieMock);

            var cursusInstantie = CursusInstantieBuilder.New().Build();

            var result = _sut.DoesNotCursusInstantieExist(cursusInstantie);

            Assert.IsTrue(result);
        }
Beispiel #18
0
        private async Task <CursusInstantie> VoegCursusInstantieToe(CommCursus nieuweCursusInstantie, Cursus cursus)
        {
            var instantie = new CursusInstantie()
            {
                Startdatum = nieuweCursusInstantie.Startdatum, CursusId = cursus.Id
            };

            db.CursusInstanties.Add(instantie);
            await db.SaveChangesAsync();

            return(instantie);
        }
Beispiel #19
0
        public bool DoesNotCursusInstantieExist(CursusInstantie cursusInstantie)
        {
            var existingCursusInstanties = _repository.GetCursusInstanties();

            if (existingCursusInstanties == null)
            {
                return(false);
            }

            if (existingCursusInstanties.Where(x => DateTime.Compare(x.StartDatum, cursusInstantie.StartDatum) == 0)
                .Count(x => x.Cursus.Code.Equals(cursusInstantie.Cursus.Code)) > 0)
            {
                return(false);
            }

            return(true);
        }
Beispiel #20
0
        public void DoesCursusInstantiesExistReturnsTrueIfCursusInstanceAlreadyExist()
        {
            CursusInstantie cursusInstantieMock = CursusInstantieBuilder.New().WithStartDate(new DateTime(2020, 02, 02)).Build();

            _cursusRepositoryMock.Setup(x => x.GetCursusInstantieById(It.IsAny <int>())).Returns(cursusInstantieMock);

            var cursusInstanties = new List <CursusInstantie>
            {
                CursusInstantieBuilder.New().WithStartDate(new DateTime(2020, 02, 02)).Build(),
                CursusInstantieBuilder.New().WithStartDate(new DateTime(2020, 03, 03)).Build(),
                CursusInstantieBuilder.New().WithStartDate(new DateTime(2020, 04, 04)).Build(),
                CursusInstantieBuilder.New().WithStartDate(new DateTime(2020, 04, 04)).Build(),
                CursusInstantieBuilder.New().WithStartDate(new DateTime(2020, 04, 04)).Build()
            };

            var result = _sut.DoesCursusInstantiesExist(cursusInstanties);

            Assert.IsTrue(result);
        }
        private async Task <List <CursusInstantie> > ExtractCursusInstantieObjectsFromProcessedText(string[] processedText)
        {
            var cursusInstantieObjecten = new List <CursusInstantie>();

            for (int i = 0; i < processedText.Length; i += 5)
            {
                CursusInstantie cursusInstantieObject = await InstantiateCursusInstantieObject(i, processedText);

                if (await IsDuplicate(cursusInstantieObjecten, cursusInstantieObject))
                {
                    duplicateCount++;
                }
                else
                {
                    cursusInstantieObjecten.Add(cursusInstantieObject);
                    cursusInstantieCount++;
                }
            }
            return(cursusInstantieObjecten);
        }
Beispiel #22
0
        private static CursusDto CreateCursussesAndCursusInstantiesAndAssignThemToACursusDto(List <string> splitLines)
        {
            var cursusInstanties = new List <CursusInstantie>();
            var cursusses        = new List <Cursus>();
            var cursusDto        = new CursusDto
            {
                CursusInstanties = cursusInstanties,
                Cursussen        = cursusses
            };

            for (int i = 0; i < splitLines.Count; i += 4)
            {
                var set = splitLines.Skip(i).Take(4).ToList();
                if (set.Count > 1)
                {
                    if (set != null || set.All(x => string.IsNullOrWhiteSpace(x)))
                    {
                        var cursus          = new Cursus();
                        var cursusInstantie = new CursusInstantie();
                        cursus.Titel = set[0];
                        cursus.Code  = set[1];
                        cursus.Duur  = set[2];
                        if (!set[3].Contains("-"))
                        {
                            cursusInstantie.StartDatum = DateTime.Parse(set[3]);
                        }
                        else
                        {
                            throw new ArgumentException((i + 3).ToString());
                        }
                        cursusInstantie.Cursus = cursus;
                        cursusInstanties.Add(cursusInstantie);
                        cursusses.Add(cursus);
                    }
                }
            }

            cursusDto.Cursussen        = cursusses;
            cursusDto.CursusInstanties = cursusInstanties;
            return(cursusDto);
        }
Beispiel #23
0
 public void VoegMeerdereCursusInstantieToeMetAndereStartDatum()
 {
     using (var repo = new CursusRepository(new DatabaseContext(_options)))
     {
         //Arrange
         var cursus = new Cursus()
         {
             Cursuscode = "test",
             Duur       = 5,
             Titel      = "C# testing"
         };
         var cursusInstantie = new CursusInstantie()
         {
             Startdatum = new DateTime(2016, 10, 10),
             Cursus     = cursus
         };
         //Act
         repo.Insert(cursusInstantie);
         //Assert
         Assert.ThrowsException <DbUpdateException>(() => repo.Insert(cursusInstantie));
     }
 }
Beispiel #24
0
        public void VoegMeerdereCursusInstantiesVindSlechts1()
        {
            using (var repo = new CursusRepository(new DatabaseContext(_options)))
            {
                //Arrange
                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "C# testing"
                };
                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 10),
                    Cursus     = cursus
                };
                repo.Insert(cursusInstantie);

                var cursusInstantie2 = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 3, 10),
                    Cursus     = cursus
                };
                repo.Insert(cursusInstantie2);

                DateTime targetDateStart = new DateTime(2016, 10, 10);
                DateTime targetDateEind  = new DateTime(2016, 10, 10);


                //Act
                var result       = repo.FindBy(c => c.Startdatum >= targetDateStart && c.Startdatum <= targetDateEind);
                var resultTotaal = repo.FindAll();
                //Assert
                Assert.AreEqual(1, result.Count());
                Assert.AreEqual(2, resultTotaal.Count());
            }
        }
Beispiel #25
0
        public IActionResult Post([FromBody] CursusInstantie value)
        {
            if (!ModelState.IsValid)
            {
                var error = new Foutmelding(ErrorTypes.BadRequest, "Modelstate invalid");
                return(BadRequest(error));
            }

            try
            {
                _repo.Insert(value);
                return(Ok());
            }
            catch (DbUpdateException)
            {
                var error = new Foutmelding(ErrorTypes.DuplicateKey, "This key already exist");
                return(BadRequest(error));
            }
            catch (Exception)
            {
                var error = new Foutmelding(ErrorTypes.Unknown, "Oops, something went wrong");
                return(NotFound(error));
            }
        }
Beispiel #26
0
        public void VindCursusLijstPerWeek()
        {
            using (var repo = new CursusRepositoryMock())
            {
                //Arrange
                Assert.AreEqual(0, repo.TimesFindByCalled);

                var target = new CursusController(repo);
                var cursus = new Cursus()
                {
                    Cursuscode = "test",
                    Duur       = 5,
                    Titel      = "C# testing"
                };

                var cursusInstantie = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 10, 10),
                    Cursus     = cursus
                };
                target.Post(cursusInstantie);

                var cursusInstantie2 = new CursusInstantie()
                {
                    Startdatum = new DateTime(2016, 3, 10),
                    Cursus     = cursus
                };
                target.Post(cursusInstantie2);

                //Act
                target.GetByWeek(new DateTime(2016, 3, 10).ToString());

                //Assert
                Assert.AreEqual(1, repo.TimesFindByCalled);
            }
        }
 public void Update(CursusInstantie entity)
 {
     db.Entry(entity).State = EntityState.Modified;
 }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='value'>
 /// </param>
 public static object Post(this ICASService operations, CursusInstantie value = default(CursusInstantie))
 {
     return(Task.Factory.StartNew(s => ((ICASService)s).PostAsync(value), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
 public void Remove(CursusInstantie entity)
 {
     db.CursusInstantie.Remove(entity);
 }
        private async Task <bool> IsDuplicate(List <CursusInstantie> cursusInstantieObjecten, CursusInstantie cursusInstantieObject)
        {
            var databaseCursusInstantieObjects = await _cursusInstantieRepository.GetWhereAsync(ci => ci.StartDatum == cursusInstantieObject.StartDatum && ci.CursusId == cursusInstantieObject.CursusId);

            return(cursusInstantieObjecten.Any(cio => cio.StartDatum == cursusInstantieObject.StartDatum && cio.CursusId == cursusInstantieObject.CursusId) || (databaseCursusInstantieObjects.Count() > 0));
        }