Beispiel #1
0
        public void BadAccessTokenReturnsNotAutorized()
        {
            var userRepository       = new LocalRepository <InsideUser>();
            var contactRepository    = new Mock <IRepository <Contact> >();
            var tokenProvider        = new Mock <IAccessTokenProvider>();
            var userManager          = new Mock <IIdentityMembershipProvider>();
            var budgetRepositoryMock = new Mock <IRepository <Budget> >();
            var clientRepositoryMock = new Mock <IRepository <Client> >();
            var serverTimeMock       = new Mock <IServerTime>();

            var controller = new ExternalController(
                userRepository,
                contactRepository.Object,
                tokenProvider.Object,
                userManager.Object,
                budgetRepositoryMock.Object,
                clientRepositoryMock.Object,
                serverTimeMock.Object);



            InsideUser testUser1 = ModelHelper.TestUser1AllDataNoReferences;
            InsideUser testUser2 = ModelHelper.TestUser1AllDataNoReferences;

            testUser1.Role.Add(new InsideRole()
            {
                Name = "consultant"
            });
            testUser1.Token.Add(new Token()
            {
                AccessToken = "abc123"
            });

            userRepository.Add(testUser1);
            userRepository.Add(testUser2);

            var result = controller.GetBudgetSummary("bad acces token");

            Assert.IsInstanceOfType(result, typeof(UnauthorizedResult));
        }
Beispiel #2
0
        public void GoodAccessTokenReturnsResult()
        {
            var userRepository    = new LocalRepository <InsideUser>();
            var contactRepository = new Mock <IRepository <Contact> >();
            var tokenProvider     = new Mock <IAccessTokenProvider>();
            var userManager       = new Mock <IIdentityMembershipProvider>();
            var budgetRepository  = new LocalRepository <Budget>();
            var clientRepository  = new LocalRepository <Client>();
            var serverTimeMock    = new Mock <IServerTime>();

            var controller = new ExternalController(
                userRepository,
                contactRepository.Object,
                tokenProvider.Object,
                userManager.Object,
                budgetRepository,
                clientRepository,
                serverTimeMock.Object);

            InsideUser testUser1 = ModelHelper.TestUser1AllDataNoReferences;
            InsideUser testUser2 = ModelHelper.TestUser1AllDataNoReferences;

            var client = ModelHelper.TestClient1AllDataNoReferences;

            client.Labels.Add(new Label()
            {
                Name = "Kampanjplaneras"
            });
            client.Consultant = ModelHelper.TestConsultant;

            var client2 = ModelHelper.TestClient2AllDataNoReferences;

            client2.Consultant = ModelHelper.TestConsultant;

            testUser1.Role.Add(new InsideRole()
            {
                Name = "consultant"
            });
            testUser1.Token.Add(new Token()
            {
                AccessToken = "good acces token"
            });

            userRepository.Add(testUser1);
            userRepository.Add(testUser2);

            var jan  = new DateTime(2014, 1, 1);
            var feb  = new DateTime(2014, 2, 1);
            var mars = new DateTime(2014, 3, 1);

            serverTimeMock.Setup(s => s.RequestStarted).Returns(jan.AddDays(10));


            Budget budget1 = new Budget()
            {
                Month = feb, Value = 1500
            };;
            Budget budget2 = new Budget()
            {
                Month = jan, Value = 2000
            };

            budget1.Client = client;
            budget2.Client = client;

            budgetRepository.Add(budget1);
            budgetRepository.Add(budget2);

            clientRepository.Add(client);
            clientRepository.Add(client2);

            client.Budgets.Add(budget1);
            client.Budgets.Add(budget2);

            Budget budget3 = new Budget()
            {
                Month = feb, Value = 1000
            };
            Budget budget4 = new Budget()
            {
                Month = jan, Value = 3000
            };

            client.Budgets.Add(budget3);
            client.Budgets.Add(budget4);
            budget3.Client = client2;

            budgetRepository.Add(budget4);
            budgetRepository.Add(budget3);


            var result = controller.GetBudgetSummary("good acces token") as OkNegotiatedContentResult <BudgetMonthSummary>;

            Assert.AreEqual(-500, result.Content.diff);
            Assert.AreEqual(1, result.Content.numClients);
            Assert.AreEqual(1, result.Content.TotalClients);
        }