<commit_before>/*
 * Copyright 2008-2013 the GAP developers. See the NOTICE file at the 
 * top-level directory of this distribution, and at
 * https://develop.chiro.be/gap/wiki/copyright
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
﻿using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using Chiro.Gap.Dummies;
using Chiro.Gap.Poco.Model;
using Chiro.Gap.ServiceContracts.FaultContracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Chiro.Gap.ServiceContracts;
using Chiro.Cdf.Ioc;
using Chiro.Gap.ServiceContracts.Mappers;
using Chiro.Gap.TestDbInfo;
using System.Security.Principal;
using System.Threading;
using Chiro.Gap.ServiceContracts.DataContracts;
using System;
using Chiro.Cdf.Poco;
using Chiro.Gap.Domain;
using Moq;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using Chiro.Gap.WorkerInterfaces;
using Chiro.Gap.Services;
using GebruikersRecht = Chiro.Gap.Poco.Model.GebruikersRecht;

namespace Chiro.Gap.Services.Test
{
    /// <summary>
    /// Test op groepenservice
    /// </summary>
    /// <remarks>Blijkbaar heeft iemand mijn mocks voor de DAO weggehaald.  Dan testen we maar
    /// heel de flow.</remarks>
    [TestClass]
    public class GroepenServiceTest
    {
        public GroepenServiceTest()
        {
        }


        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion



        [ClassInitialize]
        public static void InitialiseerTests(TestContext tc)
        {
            Factory.ContainerInit();
            MappingHelper.MappingsDefinieren();
        }

        [ClassCleanup]
        public static void AfsluitenTests()
        {
        }


        /// <summary>
        /// Deze functie zorgt ervoor dat de PrincipalPermissionAttributes op de service methods
        /// geen excepties genereren, door te doen alsof de service aangeroepen is met de goede
        /// security
        /// </summary>
        [TestInitialize]
        public void VoorElkeTest()
        {
            var identity = new GenericIdentity(Properties.Settings.Default.TestUser);
            var roles = new[] {Properties.Settings.Default.TestSecurityGroep};
            var principal = new GenericPrincipal(identity, roles);
            Thread.CurrentPrincipal = principal;
        }


        /// <summary>
        /// Ophalen groepsinfo (zonder categorieën of afdelingen)
        /// </summary>
        [TestMethod]
        public void GroepOphalen()
        {
            #region Arrange

            IGroepenService svc = Factory.Maak<GroepenService>();

            #endregion

            #region Act

            GroepInfo g = svc.InfoOphalen(TestInfo.GROEP_ID);

            #endregion

            #region Assert

            Assert.IsTrue(g.ID == TestInfo.GROEP_ID);

            #endregion
        }

        /// <summary>
        /// Ophalen groepsinfo; controleert of categorieën en afdelingen meekomen.
        /// </summary>
        [TestMethod]
        public void GroepDetailOphalen()
        {
            #region Arrange

            var afdeling = new Afdeling {ID = 11};<commit_msg>Refs #705, #1250 - test groep ophalen: data access gemockt.<commit_after>/*
 * Copyright 2008-2013 the GAP developers. See the NOTICE file at the 
 * top-level directory of this distribution, and at
 * https://develop.chiro.be/gap/wiki/copyright
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
﻿using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using Chiro.Gap.Dummies;
using Chiro.Gap.Poco.Model;
using Chiro.Gap.ServiceContracts.FaultContracts;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Chiro.Gap.ServiceContracts;
using Chiro.Cdf.Ioc;
using Chiro.Gap.ServiceContracts.Mappers;
using Chiro.Gap.TestDbInfo;
using System.Security.Principal;
using System.Threading;
using Chiro.Gap.ServiceContracts.DataContracts;
using System;
using Chiro.Cdf.Poco;
using Chiro.Gap.Domain;
using Moq;
using Microsoft.VisualStudio.TestTools.UnitTesting.Web;
using Chiro.Gap.WorkerInterfaces;
using Chiro.Gap.Services;
using GebruikersRecht = Chiro.Gap.Poco.Model.GebruikersRecht;

namespace Chiro.Gap.Services.Test
{
    /// <summary>
    /// Test op groepenservice
    /// </summary>
    /// <remarks>Blijkbaar heeft iemand mijn mocks voor de DAO weggehaald.  Dan testen we maar
    /// heel de flow.</remarks>
    [TestClass]
    public class GroepenServiceTest
    {
        public GroepenServiceTest()
        {
        }


        #region Additional test attributes

        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //

        #endregion



        [ClassInitialize]
        public static void InitialiseerTests(TestContext tc)
        {
            Factory.ContainerInit();
            MappingHelper.MappingsDefinieren();
        }

        [ClassCleanup]
        public static void AfsluitenTests()
        {
        }


        /// <summary>
        /// Deze functie zorgt ervoor dat de PrincipalPermissionAttributes op de service methods
        /// geen excepties genereren, door te doen alsof de service aangeroepen is met de goede
        /// security
        /// </summary>
        [TestInitialize]
        public void VoorElkeTest()
        {
            var identity = new GenericIdentity(Properties.Settings.Default.TestUser);
            var roles = new[] {Properties.Settings.Default.TestSecurityGroep};
            var principal = new GenericPrincipal(identity, roles);
            Thread.CurrentPrincipal = principal;
        }


        /// <summary>
        /// Ophalen groepsinfo (zonder categorieën of afdelingen)
        /// </summary>
        [TestMethod]
        public void GroepOphalen()
        {
            // Flauwe test die groep met gegeven ID opvraagt, en dan gewoon
            // het ID checkt.

            #region Arrange

            var groep = new ChiroGroep{ID = 1};

            var dummyRepositoryProvider = new Mock<IRepositoryProvider>();
            dummyRepositoryProvider.Setup(src => src.RepositoryGet<Groep>())
                                   .Returns(new DummyRepo<Groep>(new List<Groep> {groep}));
            Factory.InstantieRegistreren(dummyRepositoryProvider.Object);

            IGroepenService svc = Factory.Maak<GroepenService>();

            #endregion

            #region Act

            GroepInfo g = svc.InfoOphalen(groep.ID);

            #endregion

            #region Assert

            Assert.IsTrue(g.ID == groep.ID);

            #endregion
        }

        /// <summary>
        /// Ophalen groepsinfo; controleert of categorieën en afdelingen meekomen.
        /// </summary>
        [TestMethod]
        public void GroepDetailOphalen()
        {
            #region Arrange

            var afdeling = new Afdeling {ID = 11};
{'fraction_non_alphanumeric': 0.08797146871284989, 'fraction_numerical': 0.003890630065924565, 'mean_word_length': 2.2401960784313726, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7321593', 'n_tokens_mistral': 2592, 'n_tokens_neox': 2545, 'n_words': 765}