Esempio n. 1
0
        static public void OneFieldTest()
        {
            String   sensor_id   = "28-0000055f1020";
            var      sensor      = new SensorDS18B20(sensor_id);
            Double   temperature = 36.6;
            DateTime timestamp   = DateTime.Now;
            var      measurement = new DS18B20Measurement(sensor, temperature, timestamp);
            var      config      = new ConfigurationMock("API key", 1, new Dictionary <Int32, String> {
                { 1, sensor_id }
            });
            var measurement_list = new List <Measurement> {
                measurement
            };
            ThingSpeakFeed result = ConverterMeasurement2ThingSpeakFeed.Convert(measurement_list, config);

            // First field should contain temperature
            Assert.That(result.Field1, Is.EqualTo(temperature.ToString()));
            // Other fields should be empty
            // TODO: add a helper function to make an array instead of all there FieldN properties?
            Assert.That(result.Field2, Is.Null);
            Assert.That(result.Field3, Is.Null);
            Assert.That(result.Field4, Is.Null);
            Assert.That(result.Field5, Is.Null);
            Assert.That(result.Field6, Is.Null);
            Assert.That(result.Field7, Is.Null);
            Assert.That(result.Field8, Is.Null);
            Assert.That(result.CreatedAt, Is.EqualTo(timestamp).Within(1).Seconds);
            //TODO add verification for other fields if needed
        }
Esempio n. 2
0
            public async void Should_return_NotFound_when_phone_is_Invalid()
            {
                // Arrange
                var      invalidUserId   = 0;
                var      expirationDays  = "2";
                string   key             = "User_StatusCode_404_NotFound";
                var      localizedString = new LocalizedString(key, "Not Found");
                Contacts contact         = new Contacts()
                {
                    Phone = new Phone
                    {
                        CountryCode = "123",
                        Number      = "7894561230"
                    }
                };

                ContactServiceMock.Setup(x => x.CheckValidUserByPhoneAsync(contact.Phone))
                .ReturnsAsync(invalidUserId);

                ConfigurationMock.Setup(x => x["PasswordConfig:OTPExpiryTime"])
                .Returns(expirationDays);

                LocalizerMock
                .Setup(_ => _[key]).Returns(localizedString);

                // Act
                var result = await ControllerUnderTest.ForgotPassword(contact);

                Assert.IsType <NotFoundObjectResult>(result);
            }
Esempio n. 3
0
        public static void Setup(TestContext context)
        {
            Mock <IStringLocalizer <App.Common.Resources.GlobalResource> > _globalLocalizer = new StringLocalizerMock()._globalLocalizer;
            Mock <IConfiguration> _configuration = new ConfigurationMock()._configuration;
            Mock <IMoveService>   _moveService   = new MoveServiceMock()._moveService;

            _moveController = new MoveController(_globalLocalizer.Object, _configuration.Object, _moveService.Object);
        }
Esempio n. 4
0
        public UsersTest()
        {
            IUsersRepository usersRepository = UserRepositoryMock.Build();
            IConfiguration   configuration   = ConfigurationMock.Build();

            usersController = new UsersController(
                new UsersBusiness(usersRepository, configuration),
                new PermissionCheck(usersRepository));
        }
Esempio n. 5
0
        public ReferenceDataApiClientTestFixtures WithBaseUrl(string url)
        {
            ConfigurationMock
            .SetupGet(x => x.ApiBaseUrl)
            .Returns(url);

            BaseUrl = url;

            return(this);
        }
        public void TestRegisterWithoutPhotoStoreType()
        {
            var configuration = new ConfigurationMock();

            ApplicationServices.Register(services, configuration, hostingEnvironment);

            A.CallTo(() => services.Add(
                         A <ServiceDescriptor> .That.Matches(sd =>
                                                             sd.ServiceType == typeof(IPhotoStore) &&
                                                             sd.ImplementationType == typeof(FilePhotoStore))))
            .MustHaveHappenedOnceExactly();
        }
        public void TestRegisterWithPhotoStoreType(string photoStoreTypeConfig, string expectedImplementation)
        {
            var configuration = new ConfigurationMock();

            configuration.Values["PhotoStoreType"] = photoStoreTypeConfig;

            ApplicationServices.Register(services, configuration, hostingEnvironment);

            A.CallTo(() => services.Add(
                         A <ServiceDescriptor> .That.Matches(sd =>
                                                             sd.ServiceType == typeof(IPhotoStore) &&
                                                             sd.ImplementationType.Name == expectedImplementation)))
            .MustHaveHappenedOnceExactly();
        }
Esempio n. 8
0
        public void TestCreateHttpClientExcecao()
        {
            IConfiguration config = ConfigurationMock.SetupForFailure();

            this.BaseAddress = config.GetSection("Host").Value;
            BusinessException exception = Assert.ThrowsException <BusinessException>(() =>
            {
                RestClient client = new RestClient(this.BaseAddress);
            }
                                                                                     );

            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception.GetType(), typeof(BusinessException).GetType());
        }
        private static PropertyMock CreateRuleSetProperty(ProjectMock project, string configurationName, object propertyValue)
        {
            ConfigurationMock config = project.ConfigurationManager.Configurations.SingleOrDefault(c => c.ConfigurationName == configurationName);

            if (config == null)
            {
                config = new ConfigurationMock(configurationName);
                project.ConfigurationManager.Configurations.Add(config);
            }

            var prop = config.Properties.RegisterKnownProperty(Constants.CodeAnalysisRuleSetPropertyKey);

            prop.Value = propertyValue;
            return(prop);
        }
Esempio n. 10
0
        public void Get_return_ok_test()
        {
            IConfiguration configuration = new ConfigurationMock();
            IUnitOfWork    unitOfWork    = new UnitOfWorkMock();
            IToken         token         = new Token(configuration, unitOfWork);
            UserData       user          = new UserData()
            {
                Id        = "IdTest",
                UserName  = "******",
                FirstName = "First name test",
                LastName  = "Last name test",
                Email     = "email@test"
            };
            TokenModel response = token.Get(user);

            Assert.IsTrue(response.Value != null);
        }
Esempio n. 11
0
        public void Setup()
        {
            var factory = new SQLiteConnectionFactory(new FileSystem(), "test.db");

            var attributeReader = new Mock <IAttributeReader>();

            attributeReader.Setup(mock => mock.Read()).Returns <Attribute>(null);

            var attributeReaderFactory = new Mock <IAttributeReaderFactory>();

            attributeReaderFactory
            .Setup(mock => mock.CreateFromSegments(It.IsAny <FileInfo>(), It.IsAny <IEnumerable <JpegSegment> >()))
            .Returns(attributeReader.Object);

            _configuration = new ConfigurationMock();
            _storage       = new SqliteAttributeStorage(factory, _configuration, attributeReaderFactory.Object);
        }
Esempio n. 12
0
            public async void Should_return_createdObjectResult_when_phone_is_valid()
            {
                // Arrange
                var      validUserId    = 1;
                var      expirationDays = "2";
                Contacts contact        = new Contacts()
                {
                    Phone = new Phone
                    {
                        CountryCode = "123",
                        Number      = "7894561230"
                    }
                };

                ContactServiceMock.Setup(x => x.CheckValidUserByPhoneAsync(contact.Phone))
                .ReturnsAsync(validUserId);

                ConfigurationMock.Setup(x => x["PasswordConfig:OTPExpiryTime"]).Returns(expirationDays);

                ForgotPassword forgotPassword = new ForgotPassword()
                {
                    UserID        = validUserId,
                    OTPExpiryTime = DateTime.UtcNow.AddDays(Convert.ToInt16(expirationDays)),
                    ResetOTP      = ControllerUnderTest.GetOTP(),
                    ResetTime     = DateTime.UtcNow,
                    CreatedDate   = DateTime.UtcNow
                };

                var expectedResult = forgotPassword;

                UserServiceMock.Setup(y => y.CreateAsync(forgotPassword))
                .ReturnsAsync(expectedResult);

                // Act
                var result = await ControllerUnderTest.ForgotPassword(contact);

                // Assert
                Assert.IsType <CreatedResult>(result);
            }
Esempio n. 13
0
        public void Setup()
        {
            IConfiguration config = ConfigurationMock.Setup();

            this.BaseAddress = config.GetSection("Host").Value;
        }
        private static PropertyMock CreateProperty(ProjectMock project, string configurationName, object propertyValue)
        {
            ConfigurationMock config = project.ConfigurationManager.Configurations.SingleOrDefault(c => c.ConfigurationName == configurationName);
            if (config == null)
            {
                config = new ConfigurationMock(configurationName);
                project.ConfigurationManager.Configurations.Add(config);
            }

            var prop = config.Properties.RegisterKnownProperty(Constants.CodeAnalysisRuleSetPropertyKey);
            prop.Value = propertyValue;
            return prop;
        }