Thursday, November 12, 2015

Installing SQL Server && .NET 3.5 on Windows 10

Recently at work, I upgraded to Windows 10. Obviously, I needed SQL Server. Interestingly all versions I tried (2012, 2014, and 2016) are dependent on .NET 3.5. Even more interestingly, Windows 8 and Windows 10 do not come stock with .NET 3.5.

Anytime I tried to install SQL server, I would get a missing .NET 3.5 error.

When I try to install .NET 3.5 I had the following error: 0x800f081f missing source files.

I tried this and it failed, many times:
  1. Open a command prompt with administrator user rights (Run as Administrator) in DOS BOX type gpedit.msc
  2. Local Computer Policy -> Admin Templates -> System -> Specify settings for Optional Component install and component repair (way near the bottom of the right frame)
  3. Check the “Contact Windows Update Directly” box and set policy to Enabled.
  4. Close gpedit
  5. *Try this: Type in the dos box: DISM /Online /Enable-Feature /FeatureName:NetFx3 /All
  6. Or check in Control Panel and you can now check the .net 3.5 box and it should download
(I also tried using a USB drive with the source files and that failed.)

What did work for me:
  1. On this page (note screenshot above with photo): https://www.microsoft.com/en-us/software-download/windows10, hit Download Media Creation Tool.
  2. On my Windows 10 laptop, I opened this file, made a .ISO of my windows 10.
  3. I mounted said .ISO onto the E: drive (right click .ISO and click Mount).
  4. I ran command prompt as an admin.
  5. Then I ran this in command prompt (Replace E with whatever your mounted drive for Windows ends up being).
DISM /Online /Enable-Feature /FeatureName:NetFx3 /Source:E:\sources\sxs /All /LimitAccess

.. and it made me restart. And then it appeared to work. For some reason having it mounted locally worked.

On top of this, I was installing SQL Server 2014 and ran into another snag. I got stuck on Install watsonx86_cpu32_action, for a long long time.. suspected somethng was wrong and read a website here. Based on the suggestions, I went into Task Manager and had to End Task on some Windows Installer processed under the Background Processes.. and then it caused it to get past the watson freeze.

Wednesday, November 11, 2015

Angular JS: $.emit and $.on


In Angular, you sometimes need the scope/functions of another controller to be triggered by something in one controller.

For example, say you have a controller for a navigation page (Controller 1) and a Map page (controller 2) that contains changing maps. You want the navigation page to have a button that changes the map, but all of your stuff to control the Map page is in the Map controller. You can't hit those scope items or those methods.

So, you can have an onclick on the button on the Navigation page that hits the Controller 1 changeMap functions, which will $.emit 'changeMap' out.. where in Controller 2 there is an event listener $.on waiting for this to be triggered, and it will reroute you to the changeMap_Handler.

Controller 1: Navigation Page Controller
        $scope.changeMap = function () {
            $rootScope.$emit('changeMap', { fromState: $state.current.name });
            $state.go('locations');
        }   
Controller 2: Map Page Controller
    $rootScope.$on("changeMap", changeMap_Handler);  // passes it to the handler function

    // here is the handler function
    function changeMap_Handler(event, attrs) {
        $scope.changingMap = true;
        $rootScope.changingMap  = $scope.changingMap ;
        if (attrs.fromState === "someStateVariable") {
            $scope.variable = true;
        }
    }

Tuesday, November 3, 2015

Wednesday, September 2, 2015

Xamarin Test Cloud: How to deploy your tests

Step 1: Go to https://testcloud.xamarin.com/

Step 2: Login and see your dashboard.

Step 3: Click "New Test Run" on the top right. Click which type of app you want to run tests for first.

Step 4: Select devices you want to run the test on.

Step 5: Test series is how your tests will be organized on your dashboard. You can order them by the number of test runs you plan to execute. So if you are only doing 5 or so devices, it is nice to label it small. Then you can do medium and large depending on your audience.

Step 6: Take this code, fill in the details for your application (apk file, assembly directory..).. the part I blue marked out is my API key and my email address (which you will have filled in for your test run). Then go into the Apple terminal and put it in.. submit it, and your tests will be added to Test Cloud! You can login and see your runs on their website.

You can put "--category "smoke"", or whatever attribute is above your tests to only run certain ones. If you look at my previous Xamarin post, I mentioned you can have
[Test]
[Category("smoke")]  // attribute for sending only certain tests
[Category("whatever2")]
public void TestNameHere()
{

}
And you add it to the Terminal code at the end like this..!
mono packages/Xamarin.UITest.1.0.0/tools/test-cloud.exe submit ../something.ipa APIKEYHERE --devices f37a5aa9 --series "small" --locale "en_US" --user hello@world.com --assembly-dir StuffHere/bin/Debug --category "smoke"
Or for Windows command prompt, something like this and change api key to the one given to you:
Users\ctenn\Desktop\testcloud\testcloud\AAA\packages\Xamarin.UITest.1.0.0\tools\test-cloud.exe submit CCApp\testcloud\com.AAA_TESTCLOUD_14_2.apk APIKEYHERE --devices d3939da0 --series "weekend" --locale "en_US" --app-name "AAA" --user email@email.com --assembly-dir CCApp\testcloud\AAA\AAA\bin\Debug
NOTE 1: You can also use Xamarin studio, go into your Test explorer, right click (or double tap whichever it is) the test you want.. and then click to submit it to Test Cloud. (I am just a stubborn web developer who lives off of Windows and Visual Studio).

NOTE 2: General expectations for how well applications will work on devices depends heavily on the device. Goal is to find out your audience and what types of phones they use to cover the vast majority of them. It is best to get the top say 10-20 devices working as close to 100% as you can. Then work to try and support bigger audience. When you get to the 40 newest devices point, you will start seeing massive fails in performance based on their capacity to deal with new applications and you can't really expect them to work perfectly. Chances are you will have difficulty supporting more than the top 80 realistically based on those phone's ability to perform and their memory.

Sunday, August 30, 2015

Xamarin and UI Automated Tests via Test Cloud

Xamarin is used to build, test, and monitor mobile applications. There is a Xamarin Studio IDE for development, and Test Cloud for testing your application across thousands of devices, and Xamarin Insights for monitoring. You do have to pay for these services and this is good for enterprise development for apps to be released on the app store that need to be as bug free as possible.

I will be focusing on UI Automated Tests and Test Cloud. The purpose of this post is to do a basic overview of what it can do and a little kickstart into how to use Xamarin for Automated UI Testing.

UI Automated Tests are tests that perform the manual taps / scrolls / typing / other interactions a person would normally have to do (QA). These are usually the more tedious interactions and many places would save a lot of time and stress by automating these tests. It allows for QA to do their more difficult specific work and remove the manual time consuming stuff. It also sniffs out differences in different platforms and a large scope of devices. The scope of these tests are basically anything you can do with direct interaction on the phone manually, doesn't involve only the back-end (use unit tests here), and can be performed while the mobile application is being run. You have the choice of using Calabash or C# as a language for development -- at this point when I have spoken with the Xamarin team, the functionalities of both languages are now about equal and you can choose one or the other (in the past you had good coverage with C#, but full coverage using Calabash). Calabash is basically the framework with all the methods and whatnot defined for you to use to perform the testing. Now the C# Xamarin.UITest assembly has the same methods open for use too.

Let's start with how to set up a suite for testing. Purchase Xamarin licenses. Startup a new empty C# solution. Add NuGet packages for Xamarin.UITest and nunit.framework. Now you can separate some folder structure into Global, Pages, and Tests. In this main directory, you will also want to make a new class and call it AppInitializer or something like this. HERE is the Xamarin documentation for starting an app. You will get your api key from Xamarin, and the other constants are your local builds. You can choose to use an emulator or a physical device for testing.
public static class AppInitializer
    {
        const string apiKey = "YOUR_API_KEY";
        const string apkPath = "YOUR LOCAL FILE";
        const string appFile = "YOUR LOCAL FILE";
        const string bundleId = "YOUR BUNDLE ID";

        public static IApp StartApp(Platform platform)
        {
            IApp app;
            if (platform == Platform.Android)
            {
                app = ConfigureApp
                    .Android
                    .ApiKey(apiKey)
                    .ApkFile(apkPath)
                    .StartApp();
            }
           // can add another if / else here for iOS

            return app;
        }
    }
You will need a base abstract class, let's just call it Setup.cs for now..this is how you will cause the app to hit the AppInitalizer.StartApp() function every time before you run a test. You will inherit from this base class on each new Test class.
public abstract class Setup
    {
        protected IApp app;
        protected Platform platform;

        protected AbstractSetup(Platform platform)
        {
            this.platform = platform;
        }

        [SetUp]
        public virtual void BeforeEachTest()
        {
            app = AppInitializer.StartApp(platform);
            if (platform == Platform.iOS)
            {
                // implement here
            }

            if (platform == Platform.Android)
            {
                // implement here
            }

            ResetApp();

            app.Screenshot("On Home Page");
        }

        public void ResetApp()
        {
            new GlobalPage(app, platform)
                .YourMethodNameHere();
        }
    }
So, back to the 3 sections:
  • Global: you can put methods you will use throughout the whole app, enums, a methods for swiping from left or right, things you will just need all the time no matter what page you are on and so you can avoid code duplication.
  • Pages: for each page in your app you plan to test, you should have a page for it with relevant properties and methods it will need. Let's say the mobile developers named their Main Logo iOS-main-logo and Android-main-logo.. the page is a good place to map these to YOUR testing property name, such as simply mainLogo. Now this makes ease for you to deal with any tapping on this mainLogo in your testing app and it is already mapped to both the Android and iOS versions. You can write basic functions like, TapLogoGoHome() into this page so no matter what you can call this function in the tests without needed to rewrite it over and over again.
  • Tests: Below is an example of a test. You have to have a [Test] attirbute. You can optionally have a "category" attribute which means that you can run a specific "playlist" of tests for example if you don't want to run them all every time. You will use this when sending it to Test Cloud and specify the cateogory of tests to run: in this example it can be smoke or secondCategory. You can add a test to as many lists as you like, just keeping adding them on a new line.
        [Test]
        [Category("smoke")]
        [Category("secondCategory")]
        public void SwipeOpenSideMenuAndGoHome()
        {
            string tapOrSwipe = "swipe";

            new GlobalPage(app, platform)
                .OpenSideMenu(tapOrSwipe);

            new SideMenuPage(app, platform)
                .NavigateToHome();

            new HomePage(app, platform);
        }
On GlobalPage, you will find the OpenSideMenu method, which does the actual .Tap() function.
    public class GlobalPage : BasePage
    {
        protected string menuButton;

        public GlobalPage(IApp app, Platform platform)
            : base(app, platform)
        {
            if (OnAndroid)
            {
                menuButton = "MenuButton";
            }
            if (OniOS)
            {
                menuButton = "y";
            }
        }

        public void OpenSideMenu(string TapOrSwipe = "tap")
        {
            app.Tap(menuButton);
            app.ScrollUp();
            app.WaitFor(isOpen, timeout: TimeSpan.FromSeconds(5));
        }
    }
Using the REPL is necessary to get the elements on the page needed to tap/scroll to get the test working. What you do is call app.Repl() inside of your code, you right click your test and put in Debug test and drop a breakpoint on your app.Repl line. After you hit it, step forward once.. and you will see a little pop up. Type "tree" with no quotation marks and this will give you a layout of everything on the page. SEE the Xamarin Repl tree explanation. Repl specifically spits out what is on the page you are on. You need the IDs (so ask your developers to ID everything in a logical fashion!) to find out what you need to tap and whatnot. You get it from the Repl, not from going through their codebase as this is much faster. If you find something you are not sure about, you can go into the Repl console box and type queries into like app.Flash(c=>c.Class("EditText")) and it will flash the item (blink so you can see it) and so you can tell if it is the right element or not. Sometimes there is no ID, now you have to grab the item some other way such as getting a Child(), Parent(), Descendant(), Sibling(), etc and the index of it (to see which number element it is). This can be good/bad.. it requires maintenance for if the index number or structure changes, but sometimes in a face paced environment without IDs there is no other choice. With app.Query(); you can get things like a count or the text from an element.
// for IDE Xamarin Studio or Visual Studio
stuffOnScreen = app.Query(x => x.Id(ListView).Child()).Count();
var currResult = app.Query(x => x.Id(ListView).Child(stuffOnScreen - 1).Descendant())[2].Text;


// for Repl() tree to find your element
app.Flash(x => x.Button())

// Everything on the page
app.Query()

// One element on the page by index
app.Query()[0]
app.Query()[36]

// total things on page
app.Query().Count()

// Certain matching element on page
app.query(x => x.Id("refresher") 

// Flashes and finds something on the page. 
app.Flash(x => x.Id("bill_iconImageButton"))

// Tap action on page
app.Tap("some_iconImageButton")

/// note that sometimes the Next button
/// is on the keyboard, 
/// so this...
app.Flash(x => x.Id("Next"))

// brings back nothing
// but! doing this in the Repl..
app.PressEnter()

// moves the page for you out of the keyboard and onto the next page. 
// Therefore.. add this to your test method 
app.PressEnter();

Last minute tips.. use the Object Browser on the Xamarin.UITest assembly a lot with the Xamarin doucmentation, it makes a lot more sense that way. The Xamarin developers and support are great and there for you if you need it! You can use emulators or physical devices. If you normally work on OSX or don't mind it, it is easier because you can run everything (Android emulators/iOS emulators or physical devices for both) in one place and use Xamarin Studio which is fully integrated. If you are like me.. you can try doing Windows and Visual Studio to run Android and develop everything there (you CANNOT emulate iOS here unless you have a nearby Apple computer and can use it as a building environment by connecting to it.. or..), then move the files over to the OSX/Xamarin Studio environment to run the iOS tests. Likely you will have to tweak the IDs of everything in iOS and debug the tests all over again as iOS behaves differently and things are likely labeled differently, too. Good luck!

Friday, July 31, 2015

LINQ cleanup

Just a little example of some code cleanup.. it's a-OK to break out a logic into something long to get it working and give it some thought. It's great to take your work and make it better using tools like LINQ to make it easier to read and less space. There are times it is not worth it to make it smaller if its harder to read, however. Also, it can be good to cleanup code you see in large projects to make things neater!

Here is one example with 2 pieces of code for looking up a username.. you can search it by first name, last name, or both. Likely for usability the future holds a sorting feature too!

Before lots of LINQ: After putting if/else cases into "or" inside .Where of LINQ:

Tuesday, July 28, 2015

Get; Set;

Taking a step backwards from my normal posts to some more basics.. I wanted to explain Get; Set; on properties to anyone new to software. I felt like some of the descriptions online were a little non-user friendly and wanted to help clarify it. This is done in C#, but the concepts are the same idea with other languages.

        public class Person
        {
            public string Name { get; set; }
            // Let's investigate this one
            public string Phone { get; set; }
        }

        // This is called an auto-implemented property. What does this really mean?
        public string Phone { get; set; }

        // This is the longhand / what really happens / the manual way to do this. 
        private string phone;
        public string Phone
        { 
            get { return phone; }
            set { phone = value; }
        }

        // Now what is THIS doing? Example time..
        // Make a Person1 of type Person. 
        Person Person1 = new Person();

        // Add a value to the property of Person. 
        Person1.Phone = "123-4567"; // **#1 see below

        // phone field
        private string phone; 
        
        // phone property
        public string Phone // **#1 hits this first, causing you to enter the braces..
        { 
            get { return phone; } // #3 returns little case phone, which has been assigned to value as property Phone
            set { phone = value; } // #2 sets the magical VALUE to little case phone
        }

        // So now if we ask for..
        // thingy will be "123-4567";
        var thingy = Person1.Phone;

        // where do we get value from????
        // "The word value references the value that client code is attempting to assign to the property." - MSDN
        // In other words.. Microsoft took care of it for you.
        // You try to access and set a property, it knows to assign that to "value"

        // With this version, you can make a new property based on other properties / customization
        // not there is only a get here. Its like a read only value
        public string PhoneString
        {
            get
            {
                string phoneNumString = "";
                
                // null safe it! 
                if (Person.Phone == null) return string.Empty;

                // if there's an area code, add it on! 
                if (!string.IsNullOrWhiteSpace(Person.Phone.AreaCode))
                    phoneNumString = "(" + Person.Phone.AreaCode + ") " + Person.Phone.PhoneNumber;
                else phoneNumString = Person.Phone.PhoneNumber; // if not, no biggie. 

                // if there's an extension, add it on too! 
                if (!string.IsNullOrWhiteSpace(Person.Phone.Extension)) phoneNumString += "ext." + Person.Phone.Extension;
                    
                return phoneNumString;
            }
        }

        // So, running with the example above... here's what you can and can't do.. 
        // NOPE. Can't set this. There is only a get. 
        Person1.Phonestring = "(813)123-4567 ext. 1000"; // This will fail and throw you an error. ANGRY RED SQUIGGLYS. 

        // But! You can do this. And then... 
        Person1.AreaCode = "813";
        Person1.Phone = "123-4567";
        Person1.Extension = "1000";

        //  result = "(813)123-4567 ext. 1000"
        var result = Person1.Phonestring;