Esempio n. 1
0
        public async Task GetApplicationsAsync_GetResponseWith2ApplicationDtos_Ok()
        {
            var apps            = ApplicationFakeData.GetApplications();
            var unitoOfWorkMock = new Mock <IUnitOfWork <DbContext> >();
            var repositoryMock  = new Mock <IRepository <Application> >();

            repositoryMock.Setup(r => r.GetAsync()).Returns(Task.FromResult(apps));

            var repositoryFactoryMock = new Mock <IRepositoryFactory>();

            repositoryFactoryMock.Setup(r => r.CreateRepository <Application>(unitoOfWorkMock.Object))
            .Returns(repositoryMock.Object);

            var manager = new ApplicationBusinessManager(unitoOfWorkMock.Object, repositoryFactoryMock.Object);

            var response = await manager.GetApplicationsAsync();

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.IsValid);
            foreach (var item in response.Result)
            {
                Assert.IsNotNull(item.Name);
                Assert.IsNotNull(item.Id);
            }
        }
Esempio n. 2
0
        public async Task GetTogglesAsync_WithConfigs_Ok()
        {
            var app = ApplicationFakeData.GetApplications().FirstOrDefault();

            app.Configs = new List <ToggleConfig>
            {
                new ToggleConfig
                {
                    Id            = Guid.NewGuid().ToString(),
                    Version       = "v1",
                    ApplicationId = app.Id,
                    ToggleId      = Guid.NewGuid().ToString()
                }
            };
            var unitoOfWorkMock = new Mock <IUnitOfWork <DbContext> >();
            var repositoryMock  = new Mock <IRepository <Application> >();

            repositoryMock.Setup(r => r.FindIdAsync(app.Id)).Returns(Task.FromResult(app));

            var repositoryFactoryMock = new Mock <IRepositoryFactory>();

            repositoryFactoryMock.Setup(r => r.CreateRepository <Application>(unitoOfWorkMock.Object)).Returns(repositoryMock.Object);

            var manager  = new ApplicationBusinessManager(unitoOfWorkMock.Object, repositoryFactoryMock.Object);
            var response = await manager.GetTogglesAsync(app.Id);

            Assert.IsNotNull(response);
            Assert.IsNotNull(response.IsValid);
            Assert.IsNotNull(response.Result);
        }
Esempio n. 3
0
        public async Task GetApplicationsAsync_WithoutId()
        {
            var app             = ApplicationFakeData.GetApplications().FirstOrDefault();
            var unitoOfWorkMock = new Mock <IUnitOfWork <DbContext> >();
            var repositoryMock  = new Mock <IRepository <Application> >();

            repositoryMock.Setup(r => r.FindIdAsync(app.Id)).Returns(Task.FromResult(app));

            var repositoryFactoryMock = new Mock <IRepositoryFactory>();

            repositoryFactoryMock.Setup(r => r.CreateRepository <Application>(unitoOfWorkMock.Object)).Returns(repositoryMock.Object);

            var manager = new ApplicationBusinessManager(unitoOfWorkMock.Object, repositoryFactoryMock.Object);
            await manager.GetApplicationAsync(string.Empty);
        }
Esempio n. 4
0
        public async Task GetApplicationAsync_Ok()
        {
            var app             = ApplicationFakeData.GetApplications().FirstOrDefault();
            var unitoOfWorkMock = new Mock <IUnitOfWork <DbContext> >();
            var repositoryMock  = new Mock <IRepository <Application> >();

            repositoryMock.Setup(r => r.FindIdAsync(app.Id)).Returns(Task.FromResult(app));

            var repositoryFactoryMock = new Mock <IRepositoryFactory>();

            repositoryFactoryMock.Setup(r => r.CreateRepository <Application>(unitoOfWorkMock.Object)).Returns(repositoryMock.Object);

            var manager  = new ApplicationBusinessManager(unitoOfWorkMock.Object, repositoryFactoryMock.Object);
            var response = await manager.GetApplicationAsync(app.Id);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.IsValid);
            Assert.AreEqual(response.Result.Id, app.Id);
        }
Esempio n. 5
0
        public async Task GetApplicationAsync_Ok()
        {
            var abc = ApplicationFakeData.GetApplicationDtoABC();

            var mock = new Mock <IApplicationBusinessManager>();

            mock.Setup(applicationBusinessManager => applicationBusinessManager.GetApplicationAsync(abc.Id)).Returns(Task.FromResult(ApplicationFakeData.GetResponseWithAbcApplicationDto()));

            using (var controller = new ApplicationController(mock.Object))
            {
                var responseActionResult = (await controller.GetApplicationAsync(abc.Id)) as OkNegotiatedContentResult <Response <ApplicationDto> >;
                Assert.IsNotNull(responseActionResult);
                Assert.IsNotNull(responseActionResult.Content);
                Assert.IsNotNull(responseActionResult.Content.Result);
                Assert.IsNotNull(responseActionResult.Content.Result.Id);
                Assert.IsNotNull(responseActionResult.Content.Result.Name);

                Assert.AreEqual(abc.Id, responseActionResult.Content.Result.Id);
                Assert.AreEqual(abc.Name, responseActionResult.Content.Result.Name);
            }
        }
Esempio n. 6
0
        public async Task GetApplicationAsync_Ok()
        {
            var abc = ApplicationFakeData.GetApplicationDtoABC();

            var mock = new Mock <IApplicationBusinessManager>();

            mock.Setup(applicationBusinessManager => applicationBusinessManager.GetTogglesAsync(abc.Id)).Returns(Task.FromResult(ToggleServiceConfigFakeData.GetResponseWith2ToggleServiceConfigDto()));

            using (var controller = new ToggleConfigController(mock.Object))
            {
                var responseActionResult = (await controller.GetTogglesAsync(abc.Id)) as OkNegotiatedContentResult <Response <IEnumerable <ToggleServiceConfigDto> > >;
                Assert.IsNotNull(responseActionResult);
                Assert.IsNotNull(responseActionResult.Content);
                Assert.IsNotNull(responseActionResult.Content.Result);

                foreach (var item in responseActionResult.Content.Result)
                {
                    Assert.IsNotNull(item.Id);
                    Assert.IsNotNull(item.Version);
                }
            }
        }
Esempio n. 7
0
        public async Task GetToggleAsync_WithoutToggleSerivcePermission()
        {
            var app = ApplicationFakeData.GetApplications().FirstOrDefault();

            app.IsToggleServiceAllowed = false;
            var unitoOfWorkMock = new Mock <IUnitOfWork <DbContext> >();
            var repositoryMock  = new Mock <IRepository <Application> >();

            repositoryMock.Setup(r => r.FindIdAsync(app.Id)).Returns(Task.FromResult(app));

            var repositoryFactoryMock = new Mock <IRepositoryFactory>();

            repositoryFactoryMock.Setup(r => r.CreateRepository <Application>(unitoOfWorkMock.Object)).Returns(repositoryMock.Object);

            var manager  = new ApplicationBusinessManager(unitoOfWorkMock.Object, repositoryFactoryMock.Object);
            var response = await manager.GetTogglesAsync(app.Id);

            Assert.IsNotNull(response);
            Assert.IsFalse(response.IsValid);
            Assert.IsNull(response.Result);
            Assert.IsNotNull(response.ErrorCode);
            Assert.IsNotNull(response.Message);
        }
Esempio n. 8
0
        public async Task GetApplicationsAsync_GetResponseWithErrorCodeAndMessage_Ok()
        {
            var mock = new Mock <IApplicationBusinessManager>();

            mock.Setup(applicationBusinessManager => applicationBusinessManager.GetApplicationsAsync()).Returns(Task.FromResult(ApplicationFakeData.GetResponseWithErrorCodeAndMessage()));

            using (var controller = new ApplicationController(mock.Object))
            {
                var responseActionResult = await controller.GetApplicationsAsync() as OkNegotiatedContentResult <Response <IEnumerable <ApplicationDto> > >;

                Assert.IsNotNull(responseActionResult);
                Assert.IsNotNull(responseActionResult);
                Assert.IsNotNull(responseActionResult.Content.ErrorCode);
                Assert.IsNotNull(responseActionResult.Content.Message);
                Assert.IsFalse(responseActionResult.Content.IsValid);
                Assert.IsNull(responseActionResult.Content.Result);
            }
        }
Esempio n. 9
0
        public void GetApplications()
        {
            var apps = ApplicationFakeData.GetApplications();

            AssertApplications(apps);
        }